Abstract Factory (Abstract Factory mode, Toolkit)
It is the most abstract and general form of the factory model in all forms. Through the interface provided by the abstract factory, the client can create product objects in multiple products without specifying specific product types.
Applicability:
1. A system must be unrelated to how its product class is constructed, combined, and presented.
2. A system must be associated with one of the product families.
3. Agree that products of the product family are used together. This is an important constraint that must be reflected in the system design.
4. You provide a product library that only displays their interfaces rather than implementations, so that the client does not rely on implementation.
Structure:
1. Abstract Factory: Declares the interface for building (production) Abstract Factory Product Operations.
2. The specific factory (cconcretefactory): implements the operation of building (production) Abstract products.
3. Abstract product: Declares the interface of a certain type of object.
4. Product (cconcreteproduct): A product object to be built is defined relative to a specific factory. And implements the abstract product interface.
5. Customer (cclient): Build and obtain the final product object by using the abstract factory and the interface of the abstract product declaration.
Generally, a factory-class instance is created at runtime. And create the specific products for the specific factory respectively. To build different product objects, you must use different factories. The abstract factory provides an interface for producing products, but instead of building these products, it entrusts a factory of Its Derived classes to create product objects.
UML diagram:
Temporarily omitted. Haha
CodeTemplate:
Temporarily omitted.