Gof-java a hidden "bridge" between basic knowledge and Java EE framework knowledge

Source: Internet
Author: User

2018-1-14 by Atlas

Statement: The design mode of the fun part of the content included from the Baidu Encyclopedia Gof entry, only for individual learning and memo. Original link: Gof Baidu encyclopedia entry

Interesting insights on 23 design patterns

First of all, I would like to express my own understanding and reading the interesting views of the 23 design patterns published here by the Great God, citing a recent broadcast of the NetEase public class program "Follow Gugo Science" is a classic prologue: "Many times we are not as wise as we think, because the broken mountain thieves easy, It's hard to break a thief. To this day, the light of wisdom and the exploration of the story in the history of science is still the greatest virtue of our departure from blindfolded's ignorance. Not only the design patterns themselves, but also the preachers of design patterns, they explore the light and wisdom of the story in the design pattern, the insights and views, as well as the virtue of our detachment from blindfolded.

    • Create pattern
  • Abstract FACTORY (Abstraction Factory mode)
    Interesting solution: Chasing mm and eat, McDonald's package and KFC's package are mm love to eat things, although the taste is different, but no matter you take mm to McDonald's or KFC, just to the waiter said "two B package" on the line. McDonald's and KFC are the B-set abstract Factory, and the B package contains burgers, chicken wings and drinks. McDonald's or KFC will make burger factory, chicken wings factory, and beverage factory according to the specifications of the B package, respectively, to produce the material corresponding to the B package.
    Design idea: Customer class and factory class separate. When consumers need a set of products at any time, they simply request to the abstract factory. The abstract factory will then produce products in accordance with the product set specifications to the specific factory.

  • Builder (Construction mode)
    Interesting: mm most love to hear is "I love you" this sentence, see different places of MM, to be able to speak to her in their dialect this sentence oh, I have a multi-lingual translation machine, the above each language has a button, see mm I just press the corresponding key, it will be able to say the words "I love You" in the corresponding language, Foreign mm can easily be fixed, this is my "I love You" builder. (This must be better sold than the American translation machine used in Iraq)
    Design idea: The product's internal appearance and product generation process are separated, so that a construction process to produce a different internal representation of the product object. The construction mode allows the internal representation of the product to change independently, and the customer does not need to know the details of the product internals. The construction model can enforce a step-by-stage construction process.

  • FACTORY Method (Factory mode)
    Interesting solution: Please mm to McDonald's to eat hamburgers, different mm have different tastes, to each remember is a annoying thing, I generally use factory method mode, with mm to the waiter there, said "to a hamburger", specifically what kind of hamburger, let mm directly with the waiter said on the line.
    Design idea: The Core factory class is no longer responsible for the creation of all products, but rather the creation of the work to the sub-class to do, as an abstract factory role, is only responsible for the specific factory class must be implemented interface, and do not touch which product class should be instantiated this kind of detail.

  • PROTOTYPE (original model mode)
    Interesting: With the MM QQ chat, must say some affectionate words, I collected a lot of sweet love, need as long as copy out QQ inside on the line, this is my love prototype. (100 bucks a share, do you want it)
    Design idea: By giving a prototype object to indicate the type of object to be created, and then creating more objects of the same type with the method of copying the prototype object. The original model mode allows the product class to be dynamically increased or decreased, and the product class does not need to have any predetermined hierarchy structure, and the original model pattern applies to any hierarchy structure. The disadvantage is that each class must be equipped with a clone method.

  • SINGLETON (singleton mode)
    Interesting: I have 6 beautiful wives, their husbands are me, I am our home husband Singleton, they just say "husband", all refers to the same person, that is I (just had a dream, which has such a good thing)
    Design idea: A singleton pattern ensures that a class has only one instance, and instantiates itself and provides this instance singleton pattern to the entire system. Singleton mode should only be used when there is a real "single instance" requirement.
    • Structural mode
  • ADAPTER (Adapter mode)
    Interesting: At a friend's party met a beautiful Sarah, from Hong Kong, but I do not speak Cantonese, she can not speak Mandarin, had to resort to my friend Kent, he as my adapter between Sarah, let me and Sarah to talk to each other (I do not know if he will play me)
    Design idea: Transform the interface of a class into another interface that the client expects, so that the two classes that are unable to work together because of an interface cause mismatch can work together. The adaptation class can return an appropriate instance to the client based on the parameters.

  • Bridge (Bridges mode)
    Interesting: In the morning, meet mm, to say good morning, at night met mm, to say good evening, met mm wearing a new dress, to say that your clothes are very beautiful oh, met mm new hair, to say that your hair is very beautiful oh. Do not ask me "in the morning met mm new do a hairstyle how to say" This problem, their own use of bridge combination is not on the line.
    Design idea: The abstraction and realization decoupling, so that they can be independent changes, that is, the strong association between them into a weak association, that is, the abstraction and implementation of a software system between the use of combination/aggregation relationship rather than inheritance, so that the two can be independent changes.

  • COMPOSITE (synthetic mode)
    Fun: Mary's birthday today. "My birthday, you want to give me a gift." "Well, well, go to the store and pick your own." "This t-shirt is pretty, buy, this skirt looks good, buy, this bag is also good, buy." "Hello, bought three pieces, I only promised to send a gift of OH." "What Ah, t-shirt plus skirt plus bag, just match into a set Ah, xxx, trouble you wrap up." "" ... ", MM will use composite mode, you will not?
    Design idea: Synthetic mode organizes objects into tree structures, which can be used to describe the relationship between the whole and the parts. A compositing pattern is a pattern that handles the tree structure of an object. The composition mode represents the relationship of the part and the whole with the tree structure. The compositing mode allows the client to treat a single constituent object in the same way as a composite object made up of them.

  • DECORATOR (decorative mode)
    Interesting: Mary finished her turn to sarly birthday, or do not call her own choice, or this month's food is sure to finish, take out my last year in China on the top of the photo, write on the back "the best gift, is Love your 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 are all decorator, and finally in the decoration of my this person ah, how, understand?
    Design idea: The adornment mode extends the function of the object in a transparent manner to the client, and is an alternative to the inheritance relationship, providing more flexibility than inheritance. Dynamically adds functionality to an object that can be undone on the fly. Adds a very large amount of functionality resulting from the combination of some basic functions.

  • Facade (façade mode)
    Interesting: I have a professional Nikon camera, I like to manually adjust the aperture, shutter, so that the photo is professional, but mm can not understand these, taught a half day will not. Fortunately, the camera has facade design mode, the camera to adjust the automatic file, as long as the target to press the shutter line, everything from the camera automatically adjust, so mm can also use this camera to take a picture of me.
    Design idea: the communication between the external and a subsystem must be done through a unified façade object. Façade mode provides a high-level interface that makes subsystems easier to use. Each subsystem has only one façade class, and this façade class has only one instance, meaning it is a singleton pattern. But the entire system can have multiple façade classes.

  • FLYWEIGHT (enjoy meta mode)
    Interesting: Every day with the mm text messages, fingers are exhausted, recently bought a novice machine, you can put some commonly used sentences exist in the cell phone, to use the time, directly out, in front with the name of the MM can be sent, do not use a word a word knocked. The shared sentence is that the flyweight,mm name is the extracted external feature, which is used according to the context.
    Design idea: Flyweight is the most lightweight in a boxing match. The enjoy meta-mode efficiently supports a large number of fine-grained objects in a shared manner. The key to sharing the shared meta-mode is to differentiate between intrinsic state and external state. The intrinsic state is stored inside the element, and does not vary with the environment. The state of the outer Yun is changed with the change of the environment. The outer state can not affect the intrinsic state, they are independent of each other. Separates the states that can be shared and the states that cannot be shared from the regular class, removing the state that cannot be shared from the class. Instead of creating the shared object directly, the client should use a factory object responsible for creating the object being shared. The enjoy meta-mode significantly reduces the number of objects in memory.

  • Proxy (Agent mode)
    Interesting solution: Chat with mm in the Internet, a beginning always "Hi, hello", "Where do you come from?" "How old are you?" "How tall?" "These words, really annoying, write a program as my proxy bar, usually received these words are set up the automatic answer, received other words when I told me to answer, how, cool."
    Design idea: The proxy mode provides a proxy object for an object, and the proxy object controls the reference to the source object. An agent is a person or an institution acting on behalf of another person or an institution. In some cases, the client does not want or cannot refer directly to an object, and the proxy object can act as an intermediary directly between the customer and the target object. The client cannot distinguish between a proxy subject object and a real subject object. Proxy mode can not know the real proxy object, but only hold a proxy object interface, this time the proxy object can not create the proxy object, the proxy object must have the other role of the system to create and pass in.
    • Behavioral patterns
  • 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.

Off Topic:

Tao Nature, born in nature, hidden in nature, so-called pattern is experience and experience. All things, comprehend by analogy, as the text of the design pattern of the preacher of the concept, the fact that the experience of all walks of life is derived from living, for life. The ideal view, then as the programmer, the colorful life is also the inspiration source which designs and creates, cannot only use the life for the pure dull labor, but the fact work, the life is all so, the viewpoint does not express is suitable for the present work. As a person's growth, knowledge of learning and accumulation is on the one hand, emotional, moral, physical, such as the beginning of contact with the physique beauty of the overall training is relatively more important aspect, I think this is the quality bar, is divorced from the traditional education less subjective, less insight, give life itself creativity, create value by virtue of, Is the real sense of the so-called interests specifically to achieve value and promote social progress of the Force. I understand the positive energy, is relative, is the true real idea, is the personal inner willpower clear, unswerving yearning, willing to fire and fire. However, many people are not willing to mediocrity, willing to degenerate, but no goal, lack of ambition. I am also a line of love to do a line of character, that there is no real value to achieve their own, drag the social progress of the hind legs, ashamed unceasingly, but to maintain the courage to explore, your insistence on the spirit. The world has no way, go more people will become the road, we would like to listen to the slogan of the hand, and follow the footsteps of the old driver, as soon as possible to leave blindfolded ignorant, and then drive, shouting, carrying the next batch of passers-by, indomitable.

Gof-java a hidden "bridge" between basic knowledge and Java EE framework knowledge

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.