What is the basic difference between the Factory and Abstract Factory Patterns?
The main difference between factory pattern and abstract factory pattern is that the factory pattern provides a method of creating objects without specifying the exact class used to create it while the abstract factory pattern provides a method to combine a group of individual factories without specifying their ...
The idea behind the Factory Method pattern is that it allows for the case where a client doesn't know what concrete classes it will be required to create at runtime, but just wants to get a class that will do the job while Abstract Factory pattern is best utilized when your system has to create multiple families of ...
Factory pattern is used to introduce loose coupling between objects as the factory will take care of all the instantiation logic hiding it from the clients. Prototype pattern on the other hand is used when the cost of creating an object is large and it is ok to copy an existing instance than creating a new instance.
The facade pattern is used when you want to hide an implementation or it is about changing interface of some class or set of classes. Builder hides the process of construction by decomposing it in smaller steps. Abstract factory pattern is used when you want to hide the details on constructing instances.
With the Factory pattern, you produce instances of implementations (Apple
, Banana
, Cherry
, etc.) of a particular interface -- say, IFruit
.
With the Abstract Factory pattern, you provide a way for anyone to provide their own factory. This allows your warehouse to be either an IFruitFactory
or an IJuiceFactory
, without requiring your warehouse to know anything about fruits or juices.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With