Summarize the simple factory - "factory -" abstract factory

A simple factory:         

         1. A specific factory role: This is the core of this model and contains certain business logic and judgment logic. In java it is often implemented by a concrete class. Internal logical judgment to create products.

         2. An abstract product role: it is generally a parent class inherited by a specific product or an interface implemented. In java, it is implemented by an interface or an abstract class.

         3. Multiple specific product roles: The object created by the specific factory class is an instance of this role.

B factory pattern:         

         1. An abstract factory role: This is the core of the factory method pattern, and it has nothing to do with the application. It is an interface that a specific factory role must implement or a parent class that must be inherited. In java it is implemented by abstract classes or interfaces.

         2. Multiple specific factory roles: It contains codes related to specific business logic. Called by the application to create the corresponding product-specific object. In java it is implemented by concrete classes. Each concrete factory class can only create one instance of the concrete product class.         

         3. An abstract product role: it is the parent class inherited by the concrete product or the interface implemented. In java, there are generally abstract classes or interfaces to implement.

         4. Multiple specific product roles: The object created by a specific factory role is an instance of this role. It is implemented by concrete classes in java.

 

Product Family: A family of products with related functions located in different product hierarchy structures. The abstract factory pattern also meets the following conditions:

1. There are multiple product families in the system, and the system can only consume one family of products at a time.

2. Products belonging to the same product family are used for their use.

 

C abstract factory pattern:         

         1. An abstract factory role: This is the core of the factory method pattern, and it has nothing to do with the application. It is an interface that a specific factory role must implement or a parent class that must be inherited. In java it is implemented by abstract classes or interfaces.

         2. Multiple specific factory roles: It contains codes related to specific business logic. Called by the application to create the corresponding product-specific object. In java it is implemented by concrete classes. Each concrete factory class can only create multiple instances of the concrete product class.         

         3. Multiple abstract product roles: it is the parent class inherited by the concrete product or the implemented interface. In java, there are generally abstract classes or interfaces to implement.

         4. Multiple specific product roles: The object created by a specific factory role is an instance of this role. It is implemented by concrete classes in java. Each abstract product class can derive multiple concrete product classes.

Summarize:

Factory Method Pattern: An abstract product class that can derive multiple concrete product classes. An abstract factory class can derive multiple concrete factory classes. Each concrete factory class can only create one instance of the concrete product class.

Abstract factory pattern: Multiple abstract product classes, each abstract product class can derive multiple concrete product classes. An abstract factory class can derive multiple concrete factory classes. Each concrete factory class can create multiple instances of the concrete product class.

the difference:    

1. The factory method pattern has only one abstract product class, while the abstract factory pattern has multiple.    

2. The concrete factory class of the factory method pattern can only create an instance of a concrete product class, while the concrete factory class of the abstract factory pattern can create multiple instances of the concrete product class.  

   Note: The factory method pattern is for a product hierarchy; the abstract factory pattern is for multiple product hierarchy (a product family).

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324960451&siteId=291194637