You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Abstract Factory pattern is one of the Creational Design pattern and almost similar to Factory Pattern except the fact that its more like factory of factories.
If you are familiar with factory design pattern in java, you will notice that we have a single Factory class that returns the different sub-classes based on the input provided and factory class uses if-else or switch statement to achieve this.
Structure
It consists of AbstractFactory, ConcreteFactory, AbstractProduct, ConcreteProduct and Client.
AbstractFactory: An interface that will contain the methods for creating the products.
ConcreteFactory: A class that will implement the AbstractFactory and will be responsible for creating the products.
AbstractProduct: An interface that will contain the methods for the products.
ConcreteProduct: A class that will implement the AbstractProduct and will be responsible for the products.
Client: A class that will use the AbstractFactory and AbstractProduct interfaces for creating a family of related objects.
Abstract Factory pattern provides approach to code for interface rather than implementation.
Abstract Factory pattern is “factory of factories” and can be easily extended to accommodate more products, for example we can add another sub-class SUV and a factory SUVFactory.
Similarity with other patterns
It is similar to the factory pattern, but the factory pattern is used to create the objects of a single type.