I. Description of the pattern
There are a series of objects in my program, like we're going to have a bowl of rice, a cup of coffee (Coffee) ..., to take advantage of them, we have to generate them in the program according to the user's requirements, and then call the new operator one at a, This way the client will know the corresponding class information, the generated code is obviously not flexible. So we can not use the specific classes in the code, but just to show what we need, and then we can get the object we want?
This is certainly possible, according to Gof in the book "Design Patterns", to create objects such work should be in the creation pattern. Friends who are familiar with the intent of various design patterns will quickly conclude that "providing an interface to create a series of interrelated or interdependent objects without specifying their specific classes", at least "without specifying their specific classes", meets our requirements. OK, that's the intention of the abstract factory model.
Second, the mode of intent
Provides an interface to create a series of related or interdependent objects without specifying their specific classes.
UML Diagram of Pattern:
Iv. Model Participants
Abstract Factory role: This role is at the heart of the factory approach model, which is irrelevant to the business logic of the application system.
Specific factory (concrete Factory) Role: This role creates an instance of the product directly under the call of the client. This role contains the logic to choose the right product object, which is closely related to the business logic of the application system.
Abstract Product Role: The class that holds this role is the parent class of objects created by the factory method pattern, or the interfaces they share.
Specific product (concrete product) Role: Any Product object created by the abstract factory pattern is an instance of a specific product class. This is what the client ultimately needs, and its interior must be full of the business logic of the application system.