Abstract Factory Patterns function as a super-factory, generating other factories. The pattern is also known as a Factory of factories. In the Abstract Factory pattern, an interface is in charge of generating a factory of related or dependent objects without specifying their specific classes.
Abstract Factory Pattern with UML diagram
The UML class diagram above defines the following classes, interfaces, and objects:
AbstractFactory: This interface is used to generate an abstract product.
ConcreteFactory: This class uses the AbstractFactory interface to build concrete items.
AbstractProduct: This interface declares the type of product.
ConcreteProduct: This is a class that uses the AbstractProduct interface to generate a product.
Client: This class uses the AbstractFactory and AbstractProduct interfaces to build a family of linked objects.
When should we use the Abstract Factory pattern?
The abstract factory pattern is useful in the following cases:
Create a collection of related or dependent things that must be used together.
Configure the system to function with multiple product families.
The production of items should be independent of the system.