Factory method Mode: Defines a factory interface that creates product objects, deferring actual creation to subclasses. The Core factory class is no longer responsible for the creation of the product, so that the core class becomes an abstract factory role and is responsible only for the interfaces that the specific factory subclasses must implement, and the benefit of abstraction is that the factory method pattern allows the system to introduce new products without modifying the specific factory roles.
Factory (Abstract Factory role): This is the core of the factory method pattern, which is independent of the application. Any factory class of objects created in the schema must implement this interface.
Concretefactory (Specific factory role): This is the specific factory class that implements the abstract factory interface, contains logic that is closely related to the application, and is called by the application to create the Product object.
Product (abstract product role): The common parent or co-owned interface of the production object created by the factory method pattern.
Concreteproduct (Specific product role): This role implements the interface defined by the abstract product role. A specific product has a specific factory-created, often one by one correspondence between them.
The difference between a factory method pattern and a simple factory model:
Simple Factory mode: determines which product class object is created by the parameters passed in, and the core factory class is responsible for the creation of the specific product class object, resulting in the need to modify the core factory class each time a new product class is added.
Factory method Mode: The Core factory class is responsible for defining only the methods that a specific factory subclass must implement, no longer responsible for the creation of specific products, and deferring the actual creation work to the specific factory subclass.
Factory method Pattern of design pattern