Interesting explanation of design pattern - chasing mm
Create a model? 1, Factory is less than MM, please 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 take MM to McDonald's or KFC, only to the waiter "Come and four chicken wings". McDonald's and KFC is the Factory® factory model of producing chicken wings: 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 The most lovely to listen to "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 Every language above 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 be easily, this is My "I love you" builder. (This is certain than the translation machine used by the US military)? Construction mode: Divide the internal representation of the product and the generation process of the product, so that a construction process generates a product object with different internal items. 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 it is an annoying thing, I usually use Factory? Method mode, with MM to waiter, Say "I want a burger", what kind of burgers do, let MM tell the waiter directly. Factory Mode: The core factory class is no longer responsible for the creation of all products, but to give the specific created work to the subclass, becoming an abstract factory role, only responsible for the interface that must be implemented, not Which product class in contact should be instantiated. ? 4, prototype - chat with MM with QQ, be sure to say a little, I have collected a lot of meat love, when you need COPY to put it in QQ, this is my emoticon prototype. (100 yuan, do you want to)? Original model mode: By giving a prototype object to indicate the type of object to be created, then create more types of objects with the method of copying 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 - There are 6 beautiful wives, their husband is me, I am my husband's husband Sigleton. As long as they say "husband", they all refer to the same person, that is, I have just made a Dream, which is such a good thing)? Single-case mode: Single-case mode Make sure there is only one instance of a class, 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 Adapter between Sarah, let me talk to each other (nor do you know that he will play me)? Adapter (transformer) mode: transforms a class interface into another interface of the client, thus Make two classes that originally do not match the reasons for interfaces without 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 touched MM in the evening, I have to say good evening; I have to wear a new dress, I want to say that your clothes are so beautiful, I have encountered MM new hairstyle. To say your hair is beautiful. Don't ask me "I have encountered MM in the morning, how to say" this problem, I don't do it in combination with Bridge? Bridge mode: Diring abstractization and implementation, make the two can change independently, also That is to say, the strong correlation between them is weak, that is, uses a combination / polymerization relationship between a software system to use a combination / polymerization relationship rather than inheritance, 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? • Synthetic mode: Synthesis mode The object is organized into the tree structure, which 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 oversight roll to SARLY birthday, still don't call her own birth, otherwise this month's food fees will definitely have finished playing, take out the photo of me last year, write "best in the back" The gift is to love your fita. " We are all Decorator, eventually being modified, how do you understand? Decorative mode: Decorative mode to extend the functionality 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 yourself to adjust the aperture, the shutter, this photo is special, but MM doesn't 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 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 text messages with MM every day, the fingers are exhausted, recently bought a new phone, can put some common sentences in the mobile phone, when you use it, take it out, add MM's name You can send it, no longer use a word a word. The shared sentence is the name of Flyweight, MM is the external feature of the proposed, according to the context. • Enjoyment 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 exterior 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, always "hi, hello", "Where did you come?" "How old?" "How much is it?" These words, I am really annoying, write a The program is made as my proxy. Anyone who has received these words is set up. When you receive other words, let me know, how to answer, cool. ? Proxy mode: The 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? Ruin responsibleity - go to the English class at night, in order to soon, I sat in the last row, wow, I sat several beautiful MMs, find a note, write "Hi, Can you be 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 pass the paper to the teacher, I heard that it is an old woman. , Run!? Responsible chain mode: In the responsible chain mode, many objects are connected by each object to the reference to the reference. 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 instructions do she have to write a note to bring her brother to bring her brother. I. 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, Please eat face. ":-(? Command mode: Command mode Pack a request or operation into an object. Command mode puts the responsibility of the command and the responsibility of the execution command, delegate to different objects. Command mode Allow one of the requests to open independently, so that one party requesting the request does not have to know the interface of the requesting request, it is not necessary to know how the request is received, and when is executed, when is executed, how to execute. The system supports the undo.? 15, Interpreter - 俺 has a "Bubble MM Truth", there are all kinds of mm Raiders, such as the steps to eat Western food, go to the movie method, etc., with the MM date As long as you do an interpreter, you can do it in the above script.
• 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: "Want I want to marry you, I have to promise me"? I: "I promise," What conditions I promised, "Mary:" I look at the diamond diamond "? I:" I: "I Buy, I bought, is there? "? Mary:" I look at the villa of the lake "?" I: "I bought, I bought it, is there?" Mary: "Your little brother must With 50cm long "? My head is awkward, sitting on a chair, a bit bite:" I cut, I cut, have there? "? ......? Iterative score: Ieced Mode can sequentially access a condensed element Not necessarily to expose the gathered internal appearance. 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 for anyone who don't know, fortunately, I am next, according to the individual chips, earn money from me, lose The money is also paid, everything is OK, I got four MM's phone. • Survey mode: The stopper mode packages 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 is transformed into a pair of interactions in multiple 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. When chatting with a few MM, Memento, I must remember what I just said with MM, or MM discovered that I would be unhappy. Fortunately, I have a memo. Which MM said, what MM just said? I copied a copy of the memo to save, so you can read the previous record. ? Memo mode: The memo 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 what our company is the latest MM information? Joined the company's MM intelligence mail group, Tom is responsible for collecting information. He discovered that the new intelligence did not need a notification us, directly released to the mail group, we can receive information in time as a subscriber (observers)? Observer Mode: The observer mode defines a team of multi-dependent relationships, so that 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.