Simple factory mode Simple factory model is a class creation mode, called Static Factory Method mode. Simple factory mode is an instance of which product class is created by a factory object. Simple factory The mode is an instance of which product class is created by a factory class based on incoming parameters. Simple engineering model involves three roles such as factory role, abstract product role, and specific product role (Creator) : The role is the core of the factory method model, containing the application closeness
Offset business logic. Factory class creates a product object under the direct call of the client, it is often implemented by a specific class (2) Abstract product role (Product): The class of this role is the father of the object created by the engineering method mode
Categories, or they share the interfaces. Abstract product roles can be implemented with an interface or abstract class. (3) Concrete Product Role: Any object created by the engineering method mode is this
The role example, the specific product role is implemented by a specific class. Advantages: The core of simple factory model is factory class. This class contains the necessary judgment logic, which can determine when to create
An instance of which product class. And the client can exempt the responsibility of directly creating product objects, but only responsible for "
Fees "Products. Simple factory model achieves the segmentation of responsibility through this practice. Disadvantages: (1) When the product has a complex multi-level hierarchy structure, the factory class only has itself. It is not changed, that is, the model
Disadvantages. (2) This factory class concentrates all products creation logic, forming an omnipotent all-round class, some people put this
The class is called God class. If this all-round class does not work properly, the entire program will be affected. (3) The other disadvantage of putting so many logical sets in a class is that when the product is different Interface
When class, the factory class needs to judge when to create some kind of product. This judgment of the timing and which specific product
The judgment logic is mixed together, so that the system is difficult to expand in the future. (4) Since the simple factory model uses a static method as a factory method, the static method cannot be inherited by subclasses, so
The engineering role cannot form a hierarchical structure based on inheritance. The above disadvantages are overcome in the factory method mode.