Factory Method)
Zookeeper
The Factory method mode is the class creation mode, also known as the Virtual Constructor mode or the Polymorphic Factory mode.
The purpose of the factory method mode is to define a factory interface for creating product objects and postpone the actual creation to the subclass.
Structure of the factory method mode:
Abstract Factory role: this role is at the core of the factory method model and is irrelevant to the application. Any factory class that creates an object in the mode must implement this interface. In the above system, this role is played by the java interface "Abstract Factory". In actual systems, this role is often implemented using abstract java classes.
Specific factory role: the role is a specific java class that implements the abstract factory interface. The specific factory role contains the logic closely related to the application and is called by the application to create product objects. This system provides three such roles, namely, the specific java class.
Abstract Product role: the super type of the object created in the factory method mode, that is, the product object's common parent class or interfaces. In this system, this role is played by the java interface extraction product. In actual systems, this role is often implemented using abstract java classes.
Specific product role: this role implements the interface declared by the abstract product. Each object created in the factory method mode is an instance of a specific product role.
For example:
Abstract Factory is the core of the factory method model, but it does not grasp the power of killing fruits or vegetables. On the contrary, this right is handed over to sub-classes, namely AppleGardener StawberryGardener and GrapeGardener.
Code List:
Abstract Product
VcfJqyjGu7n7KTwvcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20150309/20150309082250123.png" alt = "\">
Specific product roles (grape)
Specific product role (Strawberry)
Abstract Factory
Specific Factory (Apple)
Specific Factory (grape)
Specific factory type (Strawberry)
Zookeeper