The pattern is everywhere, it is a story of Happyfather, Happymother, and HAPPYSON. This article is purely fictitious. If there is a similarity, it is really too harder.
Behavior mode:
Chain of Responsibility --- Doglink
Definition: Multiple objects have the opportunity to handle requests, thereby avoiding coupling relationships between requesting senders and recipients
usage frequency:
Use scenario:
Happyson: "The mother will not make help me."
Happymother: "To first then then this is like this"
Happyson: "Mom will not be"
Happymother: "I will not, ask your father to go."
Happyfather: "It's so simple, you both watched TV, I finished told you"
Scenario explanation: HAPPYFATHE and Happymother have responsibilities for counseling Happyson homework, who will help
Application point: requesting not to clear the recipient, pass the request through the successor chain
Command ---- Command
Definition: Package a request to an object so that you can use different requests to parameterize the customer, queuing, request logs, and supporting the revocable operation
usage frequency:
Use scenario:
Happyfather: "KFC? I want a big bottle Coke, my wife wants a bottle Coke, my son wants a vial to take a take-out bucket"
Half an hour later
Happyfather: "Can I not have this big bottle?"
KFC sent a subsidiary: "Sorry, you are ready to pay."
Happyfather: "But Command mode supports can be revoked" "
KFC sent the goods: "I am sorry, I am just a for sale."
Scenario explanation: Fast meals are Command mode, everyone has different requests
Application point: Command declaration execution operation
Interpreter --- Interpreter
Definition: Given a language, define a representation of his literacy, and define an interpreter, this interpreter uses this representation to explain the sentence in the language
usage frequency:
Use scenario:
19 ×× year a day, Happyson nine months
Happyson: "Wow ... wow"
Happymother: "Child, his dad, diaper"
"Wow ... wow"
Happymother: "Husband, fast milk powder, son is hungry"
Happyson: "嘻 .................
Happymother: "Dear, you must see you after the meal!"
Scenario explanation: Happyson's language can only be explained by HappyMother to Happyfather listening to HAPPYMOTHER
Application point: expand the frequency of high frequency as a sentence in a simple language
Iterator --- iterator
Definition: Provide a method sequence to access the individual elements of a aggregate object, but no need to expose the internal representation of the object.
usage frequency:
Use scenario:
Happyfather: "Quick broadcast, the series of Joan kiln is diseaseless"
Happyfather: "Fast broadcast, Chinese football is more stink than my feet"
Happyfather: "Skip the central nine, all the birds can't understand"
Happyfather: "Look this, eye-catching"
HAPPYMOTHER to explode K happyfatherhappyfather: "Don't face your face, I have to go to the street tomorrow!"
It turns out that happyfather wants to see the model contest.
Scenario explanation: All TV is a collection that can be accessed
Application point: Separate access and traversal of the list from the list object and put it into the iterator object
Mediator --- Intermediaries
Definition: Encaps some columns of object interactions with one intermediary object
usage frequency:
Use scenario:
Work mobilization relationship, HAPPY is temporarily moved to ×× city, because people in the XX city are particularly difficult, so happyfather has been rented by housing intermediary: rent funds, supporting facilities only need to negotiate with the intermediary, then the intermediary is again The landlord negotiates, so it avoids direct contact with the landlord.
Scenario explanation: The intermediary has played the role of the intermediary
Application points: encapsulate interaction between objects to Mediator intermediaries
MEMENTO-memo
Definition: Under the premise that the object is not damaged, capture an internal state of an object and save this status outside of the object.
usage frequency
Use scenario:
Happymother: "There is a date of your life! Not letting you go to the toilet, actually dare to watch TV!"
Happyfather: "Today is our wedding anniversary, I am watching the marriage video that day"
Happymother: "If you have a conscience, please remember this day"
Scenario explanation: Marry recording is a memo
Application point: record objects in an instant internal state to support cancel operation mechanism
Observer --- Observer
Definition: Define a pair of dependencies between objects. When the status of an object changes, all objects that depend on its object are notified.
usage frequency:
Use scenario:
The United States attacked Iraq, Happyfather read the latest news, Happymother watched TV every day, Happyson browsed the latest news every day, the battle change, the family got the latest news through different objects
Scenario explanation: newspapers, TV, network news is dependent on Iraq's war
Other applications: When data changes, the table is used for data display, and the figure follows the change.
State - state
Definition: Allows the object to change his behavior when its internal state changes. Objects seem to change his class
usage frequency:
Use scenario:
Happyfather work is tired
Happymother: "Husband, get up and take medicine"
Happymother: "Husband, get a little fruit"
Happymother :: "Husband, don't make a family, go to rest"
Hey, this is so comfortable, happyfather is sick, I want to be on the bed for two days.
HappyMoterh: "How can you still pack the room?"
Happyfather: "I ... I am not good."
Happymother: "Pack! Decorate!"
HAPPYFATHER: "It is not so sick attitude.
Scenario explanation: Divoria and illness are two different states
Application points: put all behaviors related to a specific state in one object
Strategy --- Strategy Mode
Definition: Define a series of algorithms, package them one by one, and enable them to replace each other, this mode makes the algorithm can be independent of customers
usage frequency:
Using Scenario: The small king borrows happyfather money until the money is still still, just this day, Xiao Wang came to HAPPY home (it is a good opportunity for the account).
First knocking on side
"Happyfather:" I met our old classmates before, he also gave me 1,000 yuan, said that it is borrowed two years ago, he or not, I forgot "
Xiao Wang: "Yes, Xiao Li's memory is good, more than me"
Actually, I didn't work, the next dispel from the snake
"HAPPYFATHER:" I heard that you have a good business recently, how is the cost? Is it also on the debt? "
Xiao Wang: "It is still a red fire, the debt is basically clear"
It seems that you can only go straight.
Happyfather: "Then you have borrowed my 2000 yuan."
Scenario explanation: For this matter to Xiao Wang, Happyfather uses three ways, and the methods can be replaced with each other, and these methods have a role.
Application points: different algorithms with different categories instead of the algorithm directly encoded to the code
Template Method --- Template Method
Mode Definition: Define the skeleton of the algorithm in an operation, and delay some steps into the subclass, TemplateMethod
The product can not change the algorithm structure to redefine certain specific steps.
usage frequency:
Use scenario:
Happymother handed a HAPPYFATHER a sweater braided teaching book: "Choose you you like the style, I am cold, I will give you a sweater"
Happyfather: "You? Weaving? I didn't listen to it!"
Happymother: "What is this, with this book, the flush, I will weave!"
Scenario explanation: Sweater woven teaching books are quite a template, happymother can weave our favorite sweater according to the above style.
Other Applications: Templates can be used as an abstraction of core services, and the client layer is implemented for different business specific purposes.
Visitor ---- visitor mode
Pattern definition: Represents an operation of each element in an object structure, which allows you to do not change each element class
Premise new operations that determine this element
usage frequency:
Use scenario:
Are you worried with your own refrigerator? Happy home is also, but now you don't have to worry.
Happyfather bought a whole pig back, and also made a detailed plan: the pig's head cooked to make cold dishes,
The pig legs will be a crystal elbow, and the pig's pre-list can fill. . . . . . . But if your refrigerator is not big enough
Learn Happyfather
Scenario explanation: Different practices can be used for different locations of pigs, just like all nodes of the object, for different
Nodes use different operations.
Application Point: Visitor contains two class hierarchical: an object corresponding to the reception operation, another visitors for the operation of the elements
Design mode I love home (below) Address: http://www.9cbs.net/develop/read_article.asp? Id = 27593