Creation pattern of design pattern

             Creation mode (5 types)

              singleton pattern

Features: Guarantees that there is only one instance of a class, and provides a global access point to it.
write picture description here
advantage:

1. The singleton mode provides access to a unique instance. 2. There is only one object in the system memory, so it can save system resources.
Disadvantages : Singleton expansion is difficult

              Factory Method Pattern

Features: Define an interface for creating objects and let subclasses decide which class to instantiate. A factory method delays the instantiation of a class to its subclasses.
write picture description here
Advantages:
1. The factory method is used to create the products required by the customer, and the customer only needs to care about the factory corresponding to the required product, not the creation details, or even the class name of the specific product class.
2. It can make the factory autonomous Determining what kind of product object to create, and the details of how to create this object, are completely encapsulated inside the concrete factory.
3. When the system needs to add new products, there is no need to modify the abstract factory or the interface provided by the abstract product, no need to modify the client, and no need to modify other specific factories and products, just add a new specific factory and product. OK. It makes the extensibility of the system very good, in line with the "open-closed" principle.
Disadvantages :
When adding new products, it is necessary to write new classes and add corresponding specific factory classes, which increases to a certain extent.

              Abstract Factory Pattern

Features: Provides an interface for creating a series of related or interdependent objects without specifying their specific classes.
write picture description here
Advantages:
The abstract factory, as the name suggests, is abstract for the client, that is, the client does not need to know what is created, which can reduce the dependency between the client and the specific product class, thereby reducing the coupling degree of the system, making the Later maintenance and expansion are more convenient.
Cons:
Difficult to support changes to new products. Because the set of products that can be created has been determined in the abstract interface, if a new product needs to be added, the interface of the abstract factory needs to be changed, which involves the change of the class of the abstract factory and all its subclasses, which violates the The principle of "open-closed"

              builder mode

Features : Decouples the construction of a complex object from its representation, allowing the same construction process to create different representations. The Builder pattern is an object creation pattern.
write picture description here
Advantages:
1. The client does not need to know the details of the internal composition of the product, and the product itself is decoupled from the product creation process, so that the same creation process can create different product objects.
2. Each specific builder is relatively independent and has nothing to do with other specific builders, so it is easy to replace specific builders or add new specific builders, and users can use different specific builders to get different products. object. In line with the "open-closed" principle
3, the product creation process can be controlled more finely.
Disadvantages :
1. The products created by the builder model generally have more in common, and their components are similar. If the differences between products are very large It is not suitable for using the builder mode, so its scope of use is limited.
2. If the internal changes of the product are complex, it may result in the need to define many specific builder classes to implement such changes, resulting in the system becoming very large, increasing the difficulty of understanding the system and increasing the operating cost

              prototype mode

Features : Use prototype instances to specify the kind of objects to create, and create new objects by copying these prototypes. The prototype pattern is an object creation pattern.
write picture description here
Advantages:
1. When creating a new object instance is more complicated, using the prototype pattern can simplify the object creation process.
2. It has better scalability.
Disadvantages :
1. Each class needs to be equipped with a clone method

Guess you like

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