23 Design patterns for mm and Java

Source: Internet
Author: User

I saw this article in the Java Forum. The author has a simple metaphor for the JAVA32 model has a very good inspiration but unfortunately did not give specific meaning I added these are the simplest introduction to learn the words suggest you look at Dr. Shanhong Java and Pattern book

Create pattern
1, factory-chase mm, please eat McDonald's chicken wings and KFC chicken wings are mm love to eat, although the taste is different but not
You take mm to McDonald's or KFC just tell the waiter "Come on 4 chicken wings" on the line McDonald's and KFC is the production of chicken wings factory

Factory mode: Customer class and factory class separate consumers need a certain product at any time only to request to the factory, consumers can be connected without modification
The disadvantage of the new product is that when the product is modified, the factory class should also be modified as follows: How to create and how to provide to the client

2, builder-mm favorite to listen to is "I love you" this sentence to see the difference between the MM, to be able to use their dialect with her to say this words OH
I have a multi-lingual translator. Each language has a key to see mm I just press the corresponding key it will be able to say in the corresponding language, "I love You
"This is a foreign mm can also be easily fixed this is my" I Love You "builder (this is better than the U.S. military in Iraq with translation machine good sell)

Construction mode: Separating the product's internal representation from the product generation process to create a construction process with differentiated interior representation product object construction
The model allows the internal representation of the product to be independent. The customer does not need to know the internal details of the product construction mode can be forced to implement the seed step construction
Process

3, FACTORY method-please mm to McDonald's to eat hamburger difference mm has a different taste to remember is a boring thing I like to pick
With the factory method mode with mm to the waiter said "want a hamburger" specifically what kind of hamburger let mm directly with the waiter said on the line
The

Factory Thinking Method mode: The Core factory class is no longer responsible for all product creation, but the specific creation of the sub-class to become an abstract factory
The role is only responsible for giving specific factory classes the need to implement interfaces without touching which product class should be instantiated in this detail

4, prototype-and mm with QQ chat set to say some affectionate words I collected a lot of sweet love when need only copy out put to
QQ inside on the line this is my love prototype (100 bucks you Want)

Original model mode: By giving a prototype object to indicate what type of object you want to create and then using the Copy prototype object idea method to create more
Original model mode of the same type object allows for dynamically increasing or decreasing the product class product class does not need to have any prior determination of the hierarchical structure of the original model pattern
The disadvantage of any hierarchical structure is that each class must be equipped with a method for cloning
"All means the same person. That's me (just had a dream, which has so good)

Singleton mode: A singleton mode ensures that a class has only one example and provides this example singleton mode to the entire system by itself.
Should be used only when there is a real "single example" requirement

Structural mode

6, Adapter-met a beautiful woman at a friend's party, Sarah from Hong Kong, but I can't speak Cantonese. She can't speak Putonghua.
My friend Kent, he's a adapter between Sarah and me so that Sarah and I can talk to each other (and I don't know if he's going to play with me).

Adapter (transformer) mode: Transforms a class interface into another interface that the client expects to fail to work due to a mismatch of interface causes
Two classes can work with the appropriate class to return a suitable example to the client according to the parameters

7, bridge-morning met mm to say good morning meet mm to say evening, met mm wearing a new dress to say your clothes good drift
Light touch mm new hairstyle to say your hair is very beautiful oh don't ask me "I met mm in the morning to do a new hairstyle how to say" the problem of their own use
Bridge combination, it's okay.

Bridge mode: The abstraction and implementation decoupling allows 2 to change independently, which means that the strong association between them becomes a weak association, which means
Use a combination/aggregation relationship rather than an inheritance relationship between the abstraction and implementation of a software software system so that they can change independently

8, Composite-mary today's birthday "My birthday you want to give me a gift" "Well, go to the store, you pick" "This T-shirt is very
Nice to buy this dress nice to buy this bag also good buy "" feed bought 3 pieces ah I only promised to give a gift oh "" What ah T-shirt plus skirt plus bag
It's a good match, Miss. Please pack up "" ... "MM will use composite mode will you?

Compositing mode: The composition mode organizes objects into a tree structure that can be used to describe the overall and partial relationship composition pattern as a Process object tree structure model.
Synthesis mode to represent the part and the whole relationship in a tree structure. The compositing mode enables the client to synthesize individual constituent objects and their composite
Equal view of the object

9, decorator-mary after the turn to sarly birthday or do not call her own pick or this month of food is sure to finish take out I go
On the top of the mountain photo on the back of the "best gift is Love you Fita" and then to the street gift shop bought a picture box (selling gifts mm is also very beautiful OH
Look for the next-door art design Mike designed a beautiful box to pack up ... We're all decorator, and we're all finally decorating me.
Do you understand me?

Adornment mode: The adornment mode to the client transparently expands the object function is to inherit the relation of the alternative scheme provides more flexibility than the inheritance dynamic to
Object Additions These functions can then be dynamically undone by adding a combination of basic functions to produce a very large number of functions

10, facade-I have a professional Nikon camera I like to manually adjust the aperture, shutter so that photos are professional but mm can
Don't know how to teach for a long while the camera has facade design mode to adjust the camera to the automatic document as long as the target press the shutter on the line cut by the camera
Automatic adjustment so mm can use this camera to take a picture of me.

Façade mode: external and sub-system communication must provide a high-level interface through the façade pattern of a single Façade object, making the subsystem easier to
There is only one façade class for each subsystem and this façade class has only one example, which means that it is a singleton mode, but the whole system can have multiple façade classes.

11, flyweight-every day with mm texting fingers are exhausted recently bought a novice machine can put some common sentences in the mobile phone to use
Time to take out directly in front of the MM name can be sent without a word hit the shared sentence is FLYWEIGHTMM name is to mention
Take out the external features to use according to context conditions

Enjoy meta-mode: Flyweight in boxing, the most lightweight sharing mode efficiently supports a large number of fine-grained objects to enjoy meta-mode to
The key to sharing is to differentiate the intrinsic state and the intrinsic state of the external state stored in the inside of the element will not change with the environment. The outer state is the ring
Changes in the state of the environment can not affect the intrinsic state they are independent of each other will be able to share the state and can not share the state from the general class central separation
To exclude the shared state from the class. The client cannot create the shared object directly and should use a factory object to create the shared
Object-sharing mode drastically reduces the number of objects in memory

12, proxy-and mm in the Internet chat start always "Hi, hello", "Where do you come from?" "How old are you?" "How tall?"
? "These words are really annoying to write as a proxy for me, all the received these words are set to automatically answer when you receive other words, then notify me how to answer
Kind of cool.

Proxy mode: Proxy mode provides a proxy object to an object and is controlled by the proxy object reference to the source object the proxy is an individual or agency
Table another person or agency take action in some cases the customer does not want or cannot directly reference an object proxy object can be in the client and target object
Directly acting as a mediator the client can not distinguish between the agent-subject object and the real-subject object proxy pattern.
The proxy object is not able to create the proxy object when the proxy object must have the other role of the system to create and pass in

Behavioral patterns

13, CHAIN of responsibleity-evening to go to the English class for a good getaway sit up to the last row Wow sat in several beautiful
MM Hey find a note to write "Hi, can I be my girlfriend?" If you're not willing to pass forward, "the note goes up and down, and it spreads to the first platoon."
MM to pass the note to the teacher heard is an old maid ah run!

Responsibility chain mode: Many objects in the responsibility chain model are referenced by each object to its next

Up to form a chain of requests passed on this chain until an object on the chain decides to process this request the client does not know which object on the chain is ultimately processed
This request system can dynamically reorganize chains and assign responsibility handlers without impacting the client there are two choices: take responsibility or push the blame
A request to the other side can ultimately not be accepted by any receiving object

14, command-I have a mm home tube special strict can't meet had to rely on her brother in between the two of us to send information she to me
If you have any instructions, just write a note and let her brother bring it to me, and her brother sends a command to thank him. I asked him to eat a bowl of mixed sauce noodles.
He said: "I also give my sister 3 boyfriends command on the most stingy to ask me to eat noodles"

Command mode: The command mode encapsulates a request or operation into an Object command mode to split the command responsibility and execute the Command responsibility Division open delegation
The command pattern for distinguishing objects allows the requester and the sender to be independent so that the requester does not have to know the receiving requester interface more than to know how the request
is received and when the operation is executed and how it is executed the system supports the command undo

15, interpreter-I have a bubble mm canon above have a variety of bubble mm strategy, such as to eat Western food steps, to see the film thinking method
Wait a minute with the mm date, just make a interpreter, follow the script above.

Interpreter mode: Given a language, the interpreter pattern can define its grammatical representation and provide an interpreter for the client to use this solution
Explain how the sentence interpreter pattern in this language will describe how to use pattern design to interpret these statements in the interpreter mode after having a simple grammar
Language refers to any interpreter object that is able to interpret any combination in the interpreter pattern needs to define a class hierarchy that represents the grammar commands
It's a series of combination rules. Each Command object has an explanatory approach that represents any permutation group of objects in the Command object hierarchy that interprets the command object
Hopewell is a language.

16. iterator-I fell in love with Mary and asked her to marry her.

Mary: "You want me to marry you and promise me the conditions."

Me: "I promise you what I can say."

Mary: "I have a crush on that carat diamond."

Me: "I buy I buy it?" ”

Mary: "I have a crush on the lake house."

Me: "I buy I buy it?" ”

Mary: "I'm into that Ferrari car."

I sat on my head in a chair and said, "I'll buy it. ”

......

Iterative sub-patterns: Iterative sub-patterns can sequentially access a clustered element without exposing the aggregated interior representation multiple objects gather in the formation of the overall name
For a clustered aggregate object to be able to accommodate a group object container object Iteration sub-pattern encapsulates the iterative logic into separate sub-objects and thus separates itself from the aggregation itself
Iterative sub-mode simplifies the aggregation interface each clustered object can have one or more iteration sub-objects each iteration state can be independent of each other
Iterative algorithms can be independent of aggregate role changes

17, MEDIATOR-4 a mm playing mahjong between each other who should give who how much money is not clear fortunately, I was in the side according to the respective raise
I got the money from me, and I paid for it, and I cut it OK, I get 4 mm phone

Mediator mode: The Mediator pattern wraps the series of object interactions so that these objects do not have to interact with each other so that they can be loosely
Coupling when the role of some objects changes, it does not immediately affect the interaction of other objects to ensure that these effects can change independently of each other. Mediators
The model converts many-to-many interactions into a multi-interaction mediator model that will object behavior and Joe the About Truth) jutting que gizzard lu liling rhyme eel with South
Aw Hugh Shinny Mei Zhi godless?br>

18, memento-at the same time with a few mm chat when you have to remember what you said with mm what words or mm found will not happy OH
Fortunately, I have a memo with which mm just said what I have to copy copies of the memo in the preservation so that you can always check the previous record

Memo Mode: Memo object is a snapshot object used to store the internal state of another object the memo mode is intended to be without breaking the package condition
The object state is caught and externally stored so that it can be restored to a stored state at the appropriate time in the future.

19, observer-want to know our latest mm information? Join the company's mm intelligence mail group. Tom was responsible for gathering intelligence, and he
Discover new information without notifying us directly to the mailing group we as Subscribers (observers) can receive information in a timely manner.

Observer pattern: The Observer pattern defines the kind of multi-dependency relationship that allows multiple observer objects to listen to a Subject object at the same time.
Notifies all observer objects that they are able to automatically update themselves when the state changes

20, state-and mm when intercourse must pay attention to her state oh in the difference between the state of her behavior will be different like you asked her to go to the movies tonight
I'm not interested in you. MM will say "There is something" for you do not hate, but did not like the MM will say "Yes, but can I bring my colleague?" "Has
After liking you mm will say "What time?" How about you go to the movies after you finish the movie? "Of course, when you're watching a movie, it's good to
MM state never hated don't like to become like OH

State mode: state mode allows an object to change behavior when its internal state changes the object looks like it changed its class-like state mode
The behavior of the object of study is wrapped in a different state object, each state object belongs to an abstract state class, the state pattern is intended to be an object
When its internal state changes, its behavior also changes as the state pattern requires that each system may acquire state to create a State class subclass when the System state
The system changes the selected subclass when changing

21, strategy-and the difference between the type of mm dating to use a different strategy please have a better taste of snacks have to go to the seaside romantic
The most suitable monocular are to get mm heart I chase mm Jin sac has a lot of strategy oh

Policy mode: Policy mode encapsulates each algorithm into a separate class of common interfaces for the group algorithm so that they can replace the policy model with each other
Allows the algorithm to separate the behavior and the environment from the change policy mode without affecting the client. The Environment class is responsible for maintaining and querying the behavior of the class
Algorithms are available in specific policy classes because the algorithm and environment are independent of the algorithm and changes will not affect the environment and the client

22. TEMPLATE method--seen how to persuade girls to bed this classic article? Girls from the realization to go to bed unchanged steps are divided into
Encounter, break the deadlock, pursue, kiss, foreplay, hands-on, Caress, go in 8 big Steps (Template method) but each step
There is no way to do this, it depends on you to improvise (concrete implementation);

Template thinking Method Mode: Template Thinking method mode prepare an abstract class to implement some logic with concrete thinking method and concrete construction sub-form
After declaring some abstract way of thinking to force subclasses to implement the remainder of the logical difference subclasses can be implemented in a differentiated way of these abstract thinking methods to the remaining logic
There is a difference between the implementation of a first-class logical framework and the logical details to the specific subclass to achieve



23, visitor-Valentine's Day to give each mm bouquet of flowers and cards, but each mm to send flowers to her personal characteristics of each card
Film also to be based on personal characteristics to pick my personal what to make clear or to find the florist and gift shop owner to do the next visitor let flower shop owner according to MM characteristics
Choose the flowers so that the gift shop owner also according to the characteristics of each person to choose a card so much easier;

Visitor Pattern: The visitor pattern is to encapsulate some of the operations that are applied to some data structure element. These operations need to be modified to accept this operation
Data structures can be kept constant visitor patterns apply to data structures relative to the undecided system it has a coupling solution between the structure and the action of the structure.
Stripping allows the set of operations to be relatively free to evolve the visitor pattern, making it easy to add new operations and adding a new visitor class visitor pattern
The behavior is concentrated in a visitor object instead of being scattered across the node class when you use the visitor pattern to put as many object-browsing logic
In the visitor class instead of putting it into its subclass, the visitor pattern can be accessed across several classes of hierarchical struct members that belong to the distinguished hierarchy member class

23 Design patterns for mm and Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.