If the goal of the Factory Method is to move instances creating to subclasses, the goal of an abstract factory is to create families of related objects without depending on their specific classes. As shown in the following diagram, every factory derived from the AbstractFactory
interface has methods to create instances of two interfaces, AbstractProduct
and AnotherAbstractProduct
. The idea is that the created objects should have the same interface, whereas, the created concrete objects are different for every factory. So, if you want to get a different behavior, you can change the factory in runtime and get a full set of different objects.
Abstract Factory is used when you need to create a family of objects that do some work together. ...
No credit card required