23 MM chase with Java design patterns [rpm] http://www.chinaunix.net Author: Oriental Spider Posted: 2004-03-06 11:49:23
I saw this article in the Java Forum, with a relaxed language to more than 32 models of Java, have a good inspiration, but unfortunately, I have not given 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. [B: 9CECA65206] Created mode [/ b: 9ceca65206] 1, Factory- chasing MM can not eat, McDonald's chicken wings and KFC's wings are what MM love to eat, although the taste is different, but no matter you MM went to McDonald's or KFC, and only said to the waiter "to come four chicken wings". McDonald's and KFC is the Factory factory model for 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'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".
[B: 9CECA65206] Structural mode [/ b: 9ceca65206] 6, Adapter - I met a beautiful Sarah in a friend party, from Hong Kong, I won't speak Cantonese, she won't speak Mandarin, I have to help me. Friend Kent, he as an adapter between me and sarah, let me talk to each other (nor do you know that he will play me) Adapter (Transformer) mode: Transform a class into the client Another interface that is expected to make two classes that were originally working together due to mismatch due to interface reasons. 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. [B: 9CECA65206] Pattern [/ B: 9Ceca65206] 13, Chain of Responsibleity - go to the English lesson at night, in order to open the last row, wow, take a few beautiful MMs, find a paper Bar, write "Hi, can you be my girlfriend? If you don't want to send 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 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, Please eat face.
", Command Mode: Command Mode Package a request or operation into an object. Command mode Put the responsibility of the issued command and the responsibility of the execution command, delegate to different objects. Command mode allows the party to be requested to be independent Open, 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 whether the operation is executed, when is executed, and how to execute. System support command. 15, Interpreter - There is a "Bubble MM Truth", there are all kinds of MM's Raiders, such as the steps to eat Western food, go to the movie method, etc., as long as the MM, as long as it is an interpreter, take the top The script is executed. Interpreter mode: After a language is given, 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 explain these statements when there is a simple grammatist. The language mentioned in the interpreter mode means any combination of any interpreter object. Need in the interpreter mode Define a grade structure of a representative's order class, which is a series of combined rules. Each command object has an interpretation method that represents any interpretation of the command object. Any arrangement of objects in the level structure of the command object is A language. 16, Iterator - I love Mary, regardless of everything to marry her. Mary: "I want to marry you, I have to promise my condition" I: "What conditions I agree, you said" Mary : "I look at the diamond" I: "I bought, I bought, and?" "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, is there? "... Iterative Submatical: Iterative Submatics can sequentially access a condensed element without exposing the internal representation of the aggregated internal representation. The overall number of multiple objects is formed together, and the aggregation target is a container that can be incompatible with a set of objects. Object. Iterative Submathes encapsulate iteration logic into a separate sub-object, which is separated from the aggregate itself. Iterative sub-mode simplifies the interface of the aggregation. Each aggregate object can have one or more iterative sub-objects, each An iterative iterative state can be independent of each other. The iterative algorithm can be independent of the gathering role change. 17, Mediator - four mm play mahjong, who should give each other, how much is it, fortunately, I am next According to the individual chip count, earn money from me, pay for money, pay for money, everything is OK, I got four MM phone. Turning person mode: the mediation mode package A series of objects interacts such that these objects do not have to make each other. Thus, they can loose coupling. When the role between some objects changes, it will not affect the role between other objects, guarantee these The role can be independent of each other. The stopper mode converts multiple interactions into a pair of interactions. Mediationer mode will abstract the behavior of the object and collaborate, put the object in small scale behavior with other objects The interaction is separated. 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 just now Say what I have copied in a memo, so you can always look at the previous record. Memo mode: Memo mode is a snapshot of a snapshot used to store 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.