I saw this article in the Java Forum, the author metapuls in the 23 models of Java with a relaxed language, and there is a good inspiration role, but unfortunately, I have not given the specific meaning, I will add it behind. These are the easiest introductions. If you want to learn, I suggest you look at Dr. Yan Hong's "Java and Mode" book.
Create mode 1, factory-chasing MM can not eat, McDonald's chicken wings and KFC's chicken wings are things that MM love to eat, although the taste is different, no matter you go to McDonald's or KFC, only to wait for the waiter " Come to four chicken wings ". McDonald's and KFC is Factory that produces chicken wings
Factory model: Customer class and factory class separate. Consumers need some kind of product at any time, just request the factory. Consumers can accept new products without modification. The disadvantage is that when the product is modified, the factory class must make a corresponding revision. Such as: How to create and how to provide it to the client.
2, Builder-MM's favorite listening is "I love you" this sentence, see MM of different places, you must use their dialect to tell her this sentence, I have a variety of language translator, Each language has a button. When I see MM, I can use the corresponding key. It can use the corresponding language to say "I love you" this sentence, the foreign mm can also make it easy, this is me "I love you" builder. (This is a better selling machine for the US military in Iraq.) Construction mode: Separate the internal representation of the product and the generation process of the product, thereby generating a product object with different internal representations. The construction model makes the internal representation of the product can change independently, and customers do not have to know the details of the internal composition of the product. Construction mode can enforce the construction process of a sub-step. 3, Factory Method - Please go to McDonald's to eat burger, different mm has different tastes, you have to remember is an annoying thing, I usually use the Factory Method mode, with MM to waiter, say " A burger, what kind of burger is the specific burger, let MM say directly to the waiter. Factory Mode: The core factory is no longer responsible for the creation of all products, but will give the specific created work to the subclass, become an abstract factory role, only responsible for the interface that must be implemented, not contact Which product class should be instantiated. 4, prototype, chat with MM, must say some affection, I have collected a lot of meat love words, when you need COPY, you will go in QQ, this is my love. Prototype. (100 yuan, do you want) Original model mode: By giving a prototype object to specify the type of object to be created, then create more types of objects with a copy of this prototype object. The original model mode allows the dynamic to increase or decrease the product class, and the product class does not require any level of prior defined, the original model mode applies to any level structure. The disadvantage is that every class must be equipped with a cloning method. 5, Singleton - I have 6 beautiful wife, their husband is me, I am the husband sigleton in our family, as long as they say "husband", they all refer to the same person, that is, I have just a dream. Oh, which is such a good thing) single case mode: Single-case mode Make sure that a class has only one instance, and it is instantiated and supplied to the entire system. Single example mode should only be used when there is a real "single instance".
Structural mode 6, adapter - I met a beautiful Sarah in a friend party, from Hong Kong, but I won't speak Cantonese, she won't speak Mandarin, I have to help my friend Kent, he as me and Sarah Adapter, let me talk to Sarah (nor do you know that he will play me) Adapter (Transformer) mode: transforms a class to another interface to the client, thus The two classes that interface reasons do not match and work together can work together. The adaptation class can return a suitable instance to the client based on the parameter. 7, Bridge- I met MM in the morning, I have to say good morning, I have encountered MM in the evening, I have to say good evening; I have to wear new clothes, I want to say that your clothes are so beautiful, I've encountered MM new hairstyle, To say your hair is so beautiful. Don't ask me "I have a new MM to say" how to say "," I don't have a bridge mode with Bridge combination: the abstraction and implementation, so that the two can change independently, that is It is said that combining / polymerization relationships between the abstract and implementation of a software system rather than inheritance is referred to as a combination / polymerization relationship between the abstraction and implementation of a software system, so that the two can change independently. 8, Composite-Mary has a birthday today. "I have a birthday, you have to send me a gift." "Well, ok, go to the store, you will pick it." "This T-shirt is very beautiful, bought, this dress is good, buy, this package is also good, I bought it. "" Hey, I bought three pieces, I only promised to send a gift. "" What, T-shirt plus skirt plus bag, just match a set, Miss, trouble you. " "...", MM will use the Composite mode, have you? Synthesis mode: The synthesis mode will be organized into the tree structure and can be used to describe the overall relationship between the overall and part. The synthesis mode is a mode of processing a tree structure of an object. The synthesis pattern expressed the structure of the part and the entire relationship. The synthesis pattern allows the client to treat a separate component object and synthetic objects composed by them. 9, Decorator-Mary overtime to SARLY birthday, still don't tell her to pick it up, otherwise this month's food fees will definitely have finished playing, take out the photos I took photos in Huashan last year, and write "the best The gift is to love your fita. "After buying a gift shop to the street (the mm of selling gifts is also very beautiful), then find a beautiful box to put it up ..., We are all Decorator, and eventually modify me this person, how do you understand? Decorative mode: Decorative mode to extend the function of the object in a transparent manner, is an alternative to inheritance relationships, providing more flexibility than inheriting. Dynamically give an object increasing function, which can be revoked again. Increase a very large number of functions generated by some basic functions. 10, Facade - I have a professional Nikon camera, I like it yourself to adjust the aperture, the shutter, this photo is special, but MM does not understand these, and I will not teach for a long time. Fortunately, the camera has a FACADE design mode, adjust the camera to the automatic file, as long as the target is on the shutter, everything is automatically adjusted by the camera so that MM can also take this camera to take pictures. Facade mode: Communication with an external and a subsystem must be performed through a unified facade object. The facade model provides a high-level interface that makes the subsystem easier to use.
Each subsystem has only one facade class, and this facade class has only one instance, that is, it is a single case mode. But the entire system can have multiple facade classes. 11, Flyweight- Send a text message with MM every day, the fingers are exhausted, recently bought a new mobile phone, can put some common sentences, when you want to use, take it out, add MM's name You can send it, no longer use a word one word. The shared sentence is Flyweight, the name of the mm is the external feature extracted, according to the context. Enjoying Yuan Mode: Flyweight refers to the most exclusive level in the boxing competition. Enjoying Yuan mode is efficiently supported by sharing to support a large number of fine granular objects. The key to enjoying the element can be shared is to distinguish between the intrinsic state and the external state. The inherent state is stored inside the enjoys and does not vary with the environment. The outer state is changed as the environment changes. The outer state cannot affect the intrinsic state, which is independent of each other. The state that will be shared and the state that cannot be shared is distinguished from the conventional class, and the status of the shared cannot be shared from the class. The client cannot create a shared object directly, and a factory object should be used to create a shared object. The enjoyment mode greatly reduces the number of objects in memory. 12, proxy - chat with MM online, one start "Hi, Hello", "Where did you come?" "How old?" "How much is it?" These words, it is really annoyed, write a program As my proxy, all have the answer to these words, set the automatic answer, and let me know if you receive other words, how to answer, cool. Proxy mode: Agent mode provides a proxy object to an object and controls the reference to the source object by the proxy object. The agent is a person or a body represents another person or an institution. In some cases, customers don't want to directly reference an object, and the agent object can directly play directly to the intermediary directly. The client does not have a proxy topic object with the real subject object. The proxy model can do not know the true subject object, but only one interface of the agent object, at this time, the agent object cannot be created by the agent object, and the other role that must be available in the system is created and incorporated. Behavior mode 13, Chain of Responsibleity - go to the English class at night, in order to open the last row, wow, take a few beautiful MMs, find a note, write "hi, you can do my Girlfriend? If you don't want to pass forward ", the note is passed by a pick, bad, passing to the first row of MM to send the paper to the teacher, I heard that is an old woman, run! Responsible Chain Mode: In the liability chain mode, many objects are picked up by each object to form a chain. Requests on this chain until an object on the chain decides to handle this request. Customers don't know which object on the chain finally processes this request, and the system can reorganize the chain and assignment responsibility without affecting the client. There are two options: responsibility or push the responsibility to the next home. A request can eventually be accepted by any receiving end object. 14, Command - I have a MM home to manage very strict, I can't meet, I have to use her younger brother to transfer information between us, what is her instruction to me, write a note to bring me brother? . This is not, her brother passed another Command. In order to thank him, I invited him to eat a bowl of soy sauce, and where he said: "I will send my sister three boyfriend to Command, as you have the minimum gas, Take me to eat face. ", Command mode: Command mode package a request or operation into an object. Command mode The responsibility of the issued command and the responsibility of executing commands are separated, and delegate different objects.
The command pattern allows the request to be opened independently, so that one of the requests does not have to know the interface to receive the request, it is not necessary to know how the request is received, and when is executed, when is executed, how to be executed of. The system supports the undo. 15. Interpreter - There is a "Bubble MM Truth", there are various strategies of various MMs, such as the steps to eat Western food, go to the movie method, etc., as long as the MM, as long as I do Interpreter, photo The above script is executed. Interpreter mode: After a given language, the interpreter mode can define a representation of its grammar and provide an interpreter. The client can use this interpreter to explain the sentence in this language. The interpreter mode will describe how to use the mode design to explain these statements when there is a simple grammatist. The language mentioned in the interpreter mode means any combination of any interpreter object. In the interpreter mode, you need to define a level structure of a command class that represents a text method, that is, a series of combined rules. Each command object has an interpretation method that represents an explanation of the command object. Any arrangement combination of objects in the level of command objects is a language. 16, Iterator - I love Mary, regardless of everything to marry her. Mary: "I want me to marry you, I have to promise my condition" I: "What conditions I promised, you said," Mary: "I saw the one-channel diamond" I: "I bought, I bought , Is there? "Mary:" I look at the villa by the lake "I:" I bought, I bought, is there? "Mary:" I look at the Ferrari sports car "my head is awkward Sitting on the chair, a bit bite: "I bought, I bought, else?" ... iterative score mode: Iterative Sub-mode can sequentially access a gathering element without exposing the internal representation of the aggregation. The generally referred to as a gathering of multiple objects is aggregated, and the aggregation target is a container object that can contain a set of objects. Iterative Submatings encapsulate iteration logic into a separate sub-object to separate from the aggregate itself. The iterative sub-mode simplifies the interface of the aggregation. Each of the aggregated objects can have one or more iterative sub-objects, each iterative state of each iterative, can be independent of each other. The iterative algorithm can be independent of the aggregated role. 17, Mediator - four mm playing mahjong, who should give each other, how much money is unclear, fortunately, I am next, according to the individual chips, earn money from me, lose money I also paid it to me, everything is OK, I got four MM phone. Turpler mode: The mediation mode is packaged in a series of objects to interact, so that these objects do not have to make each other. This allows them to loose coupling. When the role between some objects changes, there is no immediate impact on other objects. Ensure that these roles can be different from each other. The mediation mode converts multiple interactions into a pair of interactions. The mediation mode is abstracted by the behavior of the object and collaboration, and the object is separated from the interaction of other objects in small scales. 18, MEMENTO, when chatting with a few MM, must remember what I just said with MM, otherwise MM discovers will not be happy, fortunately, I have a memo. Which mm said, what I said? All copied a copy in the memo, so you can read the previous record. Memo mode: Memorandum object is an object that is used to store a snapshot of another object's internal state. The purpose of the memo mode is to catch the state of an object without damaging the package, and is external, stored, so that this object can be restored to the stored state when appropriate.
19, Observer - want to know the latest MM intelligence of our company? Joined the company's MM intelligence mail group, Tom is responsible for collecting information, and the new information he discovers does not need to notify us, directly released to the mail group, we can receive information in time as a subscriber (observer) : The observer model defines a team of multi-dependent relationships, let multiple observer objects simultaneously listen to a topic object. When this topic is changed, all observer objects will be notified to enable them to automatically update themselves. 20, State - When interested with MM, be sure to pay attention to her state. Her behavior will be different in different states. For example, you will go to watch movies this evening, and MM, which is not interested, will say "there is Things, "I don't hate it, but I haven't liked MM" good, but can I bring my colleague? ", I have already said that you will say" What time? After watching the movie How about going to the bubble? ", Of course, you can see a good performance during the movie, or you can never like to become like it. Status mode: The status mode allows an object to change behavior when its internal state changes. This object looks like a class that changes it. Status mode Pack the behavior of the objects in different status objects, each state object belongs to a subclass of an abstract state class. The intent of the state mode is to make an object change in its internal state change. The status mode requires a subclass of a status class for each system possible. When the status of the system changes, the system changes the selected subclass. 21, Strategy - Dating with different types of MM, to use different strategies, some, please make a movie better, some, eat the snack effect, some go to the seaside romance, single goal is to get MM's Fang Xin I have a lot of strategy in my chasing mm kit. Policy Mode: Policy mode For a set of algorithms, each algorithm is encapsulated into an independent class with a common interface, so that they can be replaced with each other. The policy mode makes the algorithm can change without affecting the client. Strategy mode separates behavior and the environment. Environmental class is responsible for maintaining and querying behavioral classes, and various algorithms are provided in specific policy classes. Due to the algorithm and the environment independently open, the algorithm is increased or decreased, and the modifications will not affect the environment and client. 22, Template Method - Have you seen this classic article "How to convince girls to go to bed"? Girls have divided the constant steps to the unchanging steps, break the deadlock, launch pursuit, kissing, ava play, hands, caress, go in Template Method, but each step is different, there is different situations. The practice, this is to see you randomly strain (specific implementation); template method mode: Template method mode Prepare an abstract class, implement partial logic in the form of a specific method and concrete structure, then declare some abstract method to force subclasses Realize the remaining logic. Different subclasses can implement these abstraction methods in different ways, thereby different implementations of the remaining logic. A top logical framework is first developed, and the details of the logic will be made to the specific subclass. 23, Visitor - Valentine's Day, give each MM to send a bunch of flowers and a card, but each MM sent to the characteristics of her personal characteristics, each card should also pick it according to the characteristics of the individual, I A person is clear, or find a flower shop owner and gift shop owner to do Visitor, let the flower shop boss choose a bunch of flowers according to MM, so that the gift shop owner also chooses a card according to each person, so it is easy More; visitor mode: The purpose of the visitor mode is to encapsulate some operations applied to a certain data structure element. Once these operations need to be modified, the data structure that accepts this operation can remain unchanged.