creative mode

23 design patterns of java

1. Factory mode:

The client class and the factory class are separated .

Anytime a consumer needs a certain product, he simply asks the factory.

Consumers can accept new products without modification.

The disadvantage is that when the product is modified, the factory class must also be modified accordingly. Such as: how to create and how to provide to the client.

2. Construction mode:

The internal representation of the product is separated from the production process of the product, so that a construction process generates product objects with different internal representations.

The construction mode allows the internal appearance of the product to be changed independently , and the customer does not need to know the details of the internal composition of the product .

Build mode enforces a step-by-step build process .

3. Factory method ( abstract factory ) pattern:

The core factory class is no longer responsible for the creation of all products, but entrusts the specific creation work to subclasses and becomes an abstract factory role.

It is only responsible for giving the interface that the concrete factory class must implement, without touching the details of which product class should be instantiated .


The intent of this design pattern is to provide an interface for creating a series of related or interdependent objects without specifying their concrete classes.

Common situations where the abstract factory design pattern is used are:

When a system is to be created, composed and represented independently of its products;

When a system is to be configured by one of several product families;

When it is necessary to emphasize the design of a series of related product objects for joint use;

When providing a library of product classes, but only want to show their interfaces, not implementations.

The bridging design pattern should be considered for situations where you want to use an existing class, but its interface does not meet your requirements.


4. Original model mode:

Specify the type of object to be created by giving a prototype object, and then use the method of copying the prototype object to create more objects of the same type.

The primitive model mode allows dynamic addition or subtraction of product classes , product classes do not necessarily have any pre-determined hierarchical structure,

The primitive model mode is applicable to any hierarchical structure .

The disadvantage is that every class must be equipped with a clone method.

5. Singleton pattern:

The singleton pattern ensures that there is only one instance of a class , and it instantiates itself and provides this instance to the entire system.

The singleton pattern should only be used when there is a need for a true "single instance" .


Guess you like

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