First, factory methods (Factory method) mode
The meaning of the factory method pattern is to define a factory interface that creates the product objects, deferring the actual creation to the subclass. The Core factory class is no longer responsible for the creation of the product, so the core class becomes an abstract factory role that is responsible only for the interfaces that must be implemented by the specific factory subclass, so the benefit of further abstraction is that the factory method model allows the system to introduce new products without modifying the specific factory role.
Second, the factory method pattern role and structure
Abstract Factory (Creator) Role: Is the core of the factory method pattern and is independent of the application. The factory class of any object created in the schema must implement this interface.
Specific factory (concrete Creator) role: This is a 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 product objects. There are two of these roles in the above figure: Bulbcreator and Tubecreator.
Abstract product Role: The supertype of objects created by the factory method pattern, which is the common parent class of the Product object or the shared interface. In the above picture, this role is light.
Specific product (concrete product) Role: This role implements the interface defined by the abstract product role. A specific product has a specific factory to create, they often one by one correspondence.