Remaining Java Design Patterns
When we emphasize one thing, we will emphasize some things, and some less commonly used things, which are represented by "and so on, because the remaining several models are hard to see, let's use the "remaining" to represent them!
1> the creation mode is used to process the object creation process. It mainly includes the following five design modes:
Factory Method Pattern)
Abstract Factory Pattern)
Builder Pattern)
Prototype Pattern)
Singleton Pattern)
2> the structural mode is used to process the combination of classes or objects. It mainly includes the following seven design modes:
Adapter Pattern)
Bridge Pattern)
Composite Pattern)
Decorator Pattern)
Facade Pattern)
Flyweight Pattern)
Proxy Pattern)
3> the behavior pattern describes how classes or objects interact and how to assign responsibilities. It mainly includes the following 11 design patterns:
Chain of Responsibility Pattern)
Command Pattern)
Interpreter Pattern)
Iterator Pattern)
Mediator Pattern)
Memento Pattern)
Observer Pattern)
State Pattern)
Strategy Pattern)
Template Method Pattern)
Visitor Pattern)
We have already discussed 14 and the remaining 9, so let's start to explain these classified models!
The prototype mode belongs to the object creation mode. Specify the type of all created objects by providing a prototype object, and then create more objects of the same type by copying the prototype object. This is the intention of the prototype.
The bridge mode is the object structure mode. It is also known as the Handle and Body mode or Interface mode. The purpose of the bridge mode is to "decouple abstract actions and Implementation so that the two can change independently ".
Flyweight is the most lightweight in English translation, that is, "Fly magnitude" or "rainfall level". Here we use the free translation of "Enjoy yuan mode", because it can better reflect the intention of the model. The metadata mode is the object structure mode. The metadata mode supports a large number of fine-grained objects in a shared manner. The advantage of the metadata mode is that it greatly reduces the number of objects in the memory. However, it also pays a very high price to achieve this:
The responsibility chain mode is an object behavior mode. In the responsibility chain mode, many objects are connected by each object's reference to its next home to form a chain. Requests are transmitted on this chain until an object on the chain decides to process this request. The client that sends this request does not know which object on the chain will eventually process this request. This allows the system to dynamically reorganize and assign responsibilities without affecting the client:
Take our usual responsibility chain as our guide --> shift leader --> dormitory chief's responsibility to say that if a student needs to apply for something and treat the student as a client, how can we let the dormitory chief look at it first, if the dormitory Chief finds that the incident is beyond his own range, the dormitory chief will hand it over to the monitor. If the monitor finds that the incident is beyond his own rights range, the dormitory chief will hand it over to the Director, the role here is an interface. The facilitator, shift leader, and dormitory director can be seen as specific responsibilities and the client calls the interface.
The interpreter mode is the behavior mode of the class. Given a language, the interpreter mode can define a representation of its syntax and provide an interpreter at the same time. The client can use this interpreter to explain sentences in this language.
The intermediary mode is the behavior mode of objects. The Paster mode encapsulates a series of object interaction methods so that these objects do not need to be explicitly referenced to each other. So that they can be loosely coupled. When the interaction between some objects in these objects changes, the interaction between other objects is not immediately affected. So as to ensure that these interactions can change independently,
The memorandum mode is also called the Snapshot Pattern or Token mode. It is the behavior mode of an object. The memorandum object is an object used to store snapshots of the internal state of another object. The purpose of the memorandum mode is to Capture, externalize, and store the status of an object without damaging the encapsulation, in this way, this object can be restored to the stored state when appropriate in the future. The memorandum mode is often used together with the command mode and iteration submode.
The visitor mode is the behavior mode of objects. The visitor mode aims to encapsulate operations that are applied to certain data structure elements. Once these operations need to be modified, the data structure that accepts the operation can remain unchanged.
All design patterns lay the foundation for interface programming, so we need to understand the benefits of interface programming!