CHAIN of RESPONSIBILITY (responsibility chain mode)
Fun: Go to English class in the evening, in order to get away from sitting to the last row, wow, sitting in front of several beautiful mm hey, find a note, write "Hi, can do my girlfriend?" If you do not want to pass forward ", the note on one after another to pass up, bad, to the first row of MM to pass the note to the teacher, I heard that is an old xxx ah, run!
Design idea: In the responsibility chain model, many objects are connected by each object's reference to its next-generation chain. The request is passed on this chain until an object on the chain decides to process the request. The customer does not know which object on the chain is ultimately processing the request, and the system can dynamically reorganize the chain and assign responsibility without affecting the client. The processor has two choices: take responsibility or push the responsibility to the other person. A request can eventually not be accepted by any receive-side object.
Command (Order mode)
Interesting: I have a mm home tube special strict, can not meet, had to rely on her brother in between us to send information, she told me what instructions, write a note let her brother brought to me. This is not, her brother sent over a command, in order to thank him, I asked him to eat a bowl of mixed sauce noodles, how he said: "I also give my sister three boyfriend sent command, count you the most stingy, just ask me to eat noodles." ”,:-(
Design idea: The command pattern encapsulates a request or action into an object. The command mode divides the responsibility for issuing the command and the responsibility for executing the command, delegating it to different objects. The command pattern allows the requesting party to be independent of the sending party, so that the requesting party does not have to know the interface of the party receiving the request, not to know how the request was received, and whether the operation was executed, when it was executed, and how it was executed. The system supports undo of the command.
Interpreter (interpreter mode)
Interesting: I have a "bubble mm canon", which has a variety of bubble mm strategy, such as the steps to eat Western food, to see the method of the film, and so on, with mm date, as long as a interpreter, according to the above script execution on it.
Design idea: Given a language, the interpreter pattern can define a representation of its grammar and provide an interpreter at the same time. The client can use this interpreter to interpret the sentences in the language. The interpreter pattern describes how to interpret these statements using a pattern design after having a simple grammar. The language mentioned in the interpreter pattern refers to any combination that any interpreter object can interpret. In the interpreter pattern, you need to define a hierarchy of command classes that represent grammars, which is a series of composition rules. Each command object has an explanatory method that represents the interpretation of the Command object. Any permutation combination of objects in the hierarchy of command objects is a language.
ITERATOR (iterator mode)
Funny: I fell in love with Mary and asked her to marry her.
Mary: "If you want me to marry you, I have to promise my terms."
Me: "What are the terms I promise, you say?"
Mary: "I have a crush on that one-carat diamond."
Me: "I buy, I buy, still have?" ”
Mary: "I have a crush on the villa by the lake."
Me: "I buy, I buy, still have?" ”
......
Design idea: Iterative sub-patterns can sequentially access an element in a cluster without exposing the aggregated interior representation. Aggregates are collectively called aggregates, and clustered objects are container objects that can contain a set of objects. The iterative sub-pattern encapsulates the iterative logic into a separate sub-object, which is separated from the aggregation itself. Iterative sub-patterns simplify the aggregation of the interface. Each clustered object can have one or more iteration sub-objects, and the iteration state of each iteration can be independent of each other. Iterative algorithms can be independent of aggregate role changes.
Mediator (mediator mode)
Interesting: four mm playing mahjong, between each other who should give who how much money is not clear, fortunately, I was in the next, according to their respective chips count money, earn money from my here to take, lost money also pay me, everything OK, I got four mm phone.
Design idea: The Mediator pattern wraps a series of objects interacting in such a way that the objects do not have to interact with each other clearly. So that they can be loosely coupled. When the role of some objects changes, it does not immediately affect the effect of other objects. Ensure that these effects can change independently of each other. The mediator model converts many-to-many interactions into one-to-many interactions. The Mediator pattern abstracts the behavior and collaboration of objects, and separates them from the interactions of other objects on small-scale behaviors.
MEMENTO (Memo mode)
Interesting solution: At the same time with a few mm chat, be sure to remember what you said with mm what words, otherwise mm found will not happy oh, fortunately I have a memo, just with which mm said what words I have to copy a copy put into the memo inside save, so you can check the previous record at any time.
Design Idea: A Memo object is an object that is used to store a snapshot of the internal state of another object. The purpose of the memo mode is to capture the state of an object without destroying the package, and to externally and store it so that it can be restored to the stored state at the appropriate time in the future.
OBSERVER (Viewer mode)
Interesting: Want to know our company's latest mm information? Join the company's MM intelligence mail group on the line, Tom is responsible for collecting intelligence, he found the new information without a notice to us, directly to the Mail group, we as subscribers (observers) can receive information in a timely manner.
Design idea: The Observer pattern defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time. When the subject object changes in state, all observer objects are notified so that they can automatically update themselves.
State (status mode)
Interesting solution: With MM, we must pay attention to her state, oh, in different states, her behavior will be different, such as you ask her to go to the movies tonight, you are not interested in mm will say "There is something", you do not hate but still do not like the MM will say "good ah, but can bring my colleague?" "What time is it that you've already liked your mm?" Why don't you go clubbing after the movie? "Of course, you see the film in the process of good performance, you can also put the status of MM never hate to become like oh."
Design idea: State mode allows an object to change behavior when its internal state changes. This object looks like it has changed its class. State mode wraps the behavior of the object being studied in a different state object, and each state object belongs to a subclass of an abstract state class. The intent of the state pattern is to change the behavior of an object as it changes its internal state. State mode requires the creation of a subclass of a State class for each of the possible states of a system. When the state of the system changes, the system changes the selected subclass.
Strategy (Policy mode)
Interesting: With different types of mm dating, to use a different strategy, some of the film is better, some go to eat snack effect is good, some go to the seaside romantic most suitable, single purpose is to get mm heart, I chase mm Jin sac there are many strategy oh.
Design idea: The strategy model for a set of algorithms, each algorithm is encapsulated in a separate class with a common interface, so that they can be replaced with each other. The policy pattern allows the algorithm to change without affecting the client. The strategy model separates behavior from the environment. The Environment class is responsible for maintaining and querying behavior classes, and various algorithms are available in specific policy classes. Because the algorithm and the environment independent, the algorithm increases or decreases, the modification will not affect the environment and the client.
Template method (templates mode)
Interesting: Have you seen the classic article "How to persuade a girl to go to bed"? Girls from the realization of the same steps to go to bed, break the deadlock, pursue, kiss, foreplay, hands-on, caress, go into eight steps (Template method), but each step for different situations, there is not the same approach, it depends on you improvise (concrete implementation).
Design idea: Template Method schema prepares an abstract class, implements some of the logic in the form of concrete methods and concrete constructs, and then declares some abstract methods to force subclasses to implement the remaining logic. Different subclasses can implement these abstract methods in different ways, thus having different implementations of the remaining logic. First, a top-level logical framework is developed, and the details of the logic are left to the specific subclasses to implement.
- VISITOR (Visitor mode)
Interesting: Valentine's Day, to give each mm send a bouquet of flowers and a card, but each mm sent to the flowers to her personal characteristics, each card also according to the characteristics of individual to pick, I am a person who make clear, or find florist shop owner and gift shop boss do a visitor, Let flower shop owner according to the characteristics of mm choose a bouquet of flowers, so that the gift shop owner also choose a card according to each person's characteristics, so it is much easier.
Design idea: The purpose of the visitor pattern is to encapsulate some action that is applied to a data structure element. Once these operations need to be modified, the data structure that accepts the operation can remain unchanged. The visitor pattern is suitable for systems with relatively indeterminate data structures, which frees up the coupling between the structure and the operation of the structure so that the set of operations can evolve relatively freely. The visitor pattern makes it easy to add new operations, which is to add a new visitor class. The visitor pattern concentrates the behavior on a visitor object, rather than spreading it across a node class. When you use the visitor pattern, you put as much of the object-browsing logic in the visitor class as possible, rather than in its subclasses. The visitor pattern can access member classes belonging to different hierarchical structures across hierarchical structures of several classes.