In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
I. responsibility chain model
In this mode, there are senders and receivers. Typically, each receiver contains a reference to another receiver, forming a chain, and if one receiver cannot process the request, it passes the same request to the next receiver, and so on.
This mode decouples the sender and receiver of the request, but there is no guarantee that the request will be received.
The usage scenario is 1. Multiple objects can process the same request, and which object handles the request is automatically determined by the run time. two。 Submit a request to one of multiple objects without explicitly specifying the recipient. 3. A set of objects can be dynamically specified to handle requests.
Here is a particularly vivid example:
Suppose there is a demand now, first of all, the intern gets the demand.
If the intern can achieve it, achieve it directly. If not, he handed over the requirement to the junior engineer.
If the junior engineer can achieve it, achieve it directly. If not, give it to the intermediate engineer.
If the intermediate engineer can achieve it, achieve it directly. If not, give it to the senior engineer.
If the senior engineer can achieve it, achieve it directly. If not, give it to CTO.
If CTO can be implemented, it can be implemented directly. If not, tell the product directly that the demand will not be done.
There are some similarities between this model and the decorator model.
II. Command mode
According to the description of the rookie tutorial, "in software systems, there is usually a tightly coupled relationship between behavior requesters and behavior implementers, but in some situations, such as when the behavior needs to be recorded, undone or redone, transactions, and so on." this tightly coupled design that is not resistant to change is not appropriate.
I don't understand this description very well now. What I understand is that encapsulating a request with an object is equivalent to adding an extra layer between the initiator of the request and the request in order to decouple the requester from the request.
III. Parser mode
This is not very clear, feel that there is no application of the scene.
IV. Iterator mode
I don't have a deep understanding of this, and I don't feel used much.
Five. intermediary model
Used to reduce the complexity of communication between multiple objects and classes. This pattern provides a mediation class that usually handles communication between different classes and supports loose coupling, making the code easy to maintain.
The specific approach is to transform the cross-linked (network) relationship into a star relationship. 1. There are more complex reference relationships between objects in the system, which leads to confusion in the structure of dependency relations between them and it is difficult to reuse the object. 2. Want to encapsulate the behavior of multiple classes through an intermediate class, but do not want to generate too many subclasses. The disadvantage may be that intermediaries can become large and complex and difficult to maintain. The specific application has the role of c in mvc.
VI. Memo mode (less application?)
The main solution: the so-called memo mode is to capture the internal state of an object without breaking the encapsulation, and save the state outside the object, so that the object can be restored to the previously saved state later.
When to use: most of the time we need to record the internal state of an object, the purpose of this is to allow the user to cancel uncertain or wrong operations, to return to his original state, so that he has "medicine for regret" to eat.
How to solve it: specifically store object state through a memo class.
Key code: the customer is not coupled to the memo class, but to the memo management class.
Application examples: 1. Regret medicine. 2. Archiving when playing game. 3. Ctri + z in Windows. 4. Retreat in IE. 4. Transaction management of database.
Advantages: 1. Provide users with a mechanism that can restore the state, so that users can easily return to a certain historical state. 2. The encapsulation of the information is realized, so that the user does not need to care about the details of the state.
Disadvantages: consumption of resources. If the class has too many member variables, it is bound to take up a lot of resources, and each save will consume a certain amount of memory.
Seven. observer mode
The Observer pattern (Observer Pattern) is used when there is an one-to-many relationship between objects. For example, when an object is modified, its dependent objects are automatically notified. The observer model belongs to the behavioral model. Application is the event mechanism in mvc.
Eight. state mode
Encapsulate a state as an object (state object) that depends on the object that holds the state. The state object has one or more methods to change the behavior of the object that holds the state. Applications include: state machine, action node of behavior tree and so on.
Nine. Empty object mode
To be continued...
Ten. Strategic model
Intention: define a series of algorithms, encapsulate them one by one, and make them interchangeable.
Main solution: when there are many similar algorithms, the complexity and difficulty of using if...else are difficult to maintain.
When to use: there are many classes in a system, and what distinguishes them is their direct behavior.
How to solve it: encapsulate these algorithms into a class and replace them arbitrarily.
Key code: implement the same interface.
Application examples: 1. Zhuge Liang's ingenious plan, each bag is a strategy. 2. The bullet in the plane game.
Advantages: 1. The algorithm can be switched freely. 2. Avoid using multiple conditional judgments. 3. Good expansibility.
Disadvantages: 1. The number of policy classes will increase. 2. All policy classes need to be exposed.
eleven。 Template mode
To be continued...
twelve。 Visitor mode
To be continued...
To be continued
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.