Classic metaphor (Java design mode)

zhaozj2021-02-16  82

1, from: http: //dev.9cbs.net/Article/26/26772.shtm

== Creation mode ==

1, = Simple factory = I have been tired of playing basketball, just having a small stall on the side. "Come to Coke." "I want Fena." "A bottle of mineral water."

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. With a small stall, our thirsty problem is very easy solution.

2, = factory method = I have been in the afternoon, I will take a shower, come back and take a shower, and the canteen is closed. We ran over the West three doors outside to eat beef noodles (huh, one of life), every restaurant's flavor is still different, this does not matter, we just say a "bowl of beef noodles".

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. Every restaurant is a specific factory, but now the West Sanmen has turned off, depressed ing!

3, = singleton = kobe is Kobe, whether you see from TV, or see it from the newspaper, in fact, he is alone.

Single-case mode: Single-case mode Make sure that a certain class has only one instance, and it is instantiated and supplied to the entire system. There are a few, but Kobe can only have one, nonsense!

4, = builder = NBA Zhongqiang team is quite, and each has its own characteristics, so there is a different play for different teams, but you just say "Today, the king" will, how to make a coach to arrange (Build)

Construction mode: The internal representation and client of the product come, the customer does not have to know the details of the internal composition of the product, so the appearance of the product is generally used very complicated. The tactical arrangement is indeed a professional task, so ....

5, = prototype = This year, all star games are true, I really want to see it again. "Xiao Chen, open the Serv-U, I will under your all-star game." "OK! But upload two good films." "Ah, I halo ~~!"

Original model mode: actually copying. The original model mode allows dynamics to increase or reduce product classes, and the product class is suitable for any level structure. The disadvantage is that every class must be equipped with a cloning method. Fortunately, Dongdong inside Windows has a copy option.

== Structure mode ==

6, = adapter = When Yao Ming is going to the rocket, the exchange is a bit inconvenient, but through the broker Adapter, Yao Ming quickly mixed with the rocket.

Adapter mode: Transforms a class into another interface to the client, so that two classes that have been worked for by interface reasons and cannot work together. Through the broker Adapter, the head coach can regard Yao Ming as the local people (people who speak E text). Now Yao Ming has strengthened the function, making it do not want to communicate with the head coach, huh, Str Man!

7, = composite = The first half was filled with 50:25, and the middle field was suspended. Let's arrange how to hit the second half: "Solution A: No. 6 is too accurate, you have to guard against it." - "That is!" Solution B: The left defense is too weak, change the XX. "-" Good Yeah! "" Solution C: Attack is too bad, play some differences. "-" Not bad! "Scene D: first half Solution X is actually good, the second half go on. "-" Okok! "... a whistle, the second half begins, we will combine scheme A, B, C ..., set as program Y. @ # ¥% ^ & * (! ~ Wait for a series of series, we finally overcome the opponent at 51:50, haha ​​... !! Daydream # & @ *! Synthetic mode: synthetic model makes the client to put separate ingredients and The synthesis objects they have completed are equally, so the synthesis pattern makes the client add new components easy. Scheme A is a simple solution, and the program D is a complex plan formed by different plans, but we don't care These, we only know that they are all what we want.

8, = Decorator = Remember that the West side playground did not repair, we kicked the ball without the land, okay, a basketball court is empty, we have a few bricks, put two doors, haha, this, basketball court It turns into a small football field. A dance will be held in the system, you have to find a big place, we look at the basketball court, hang a lamp, move two speakers, OK, everything is done. In this way, the basketball court turned into a dance hall, haha.

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. In fact, basketball court can also become a lot of other stuff, just play your imagination, hehe.

9, = proxy = Play NBA Positive Happying. Suddenly, Xiao Fu ran over and said, "Your phone, X-system say you have to do it with our two pm, how?" - "" - "OK, I have no problem with them!" Play Games. The small payment fails to save a lot of things, huh, huh.

Agent mode: Agency is a person or a body to take action on behalf of 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. The X system only knows that we agree with them, but they don't know if they answer them.

10, = flyweight = Last time I said to eat beef noodles, there are a few very picky. This is not: "Boss, I want to spicy." - "Good!" Hey, the boss put some spicy sauce. "I want to sinate." - "Ok!" Hey, the boss put some pickles. "I also want to be Sichuan." - The boss did it again in the style of just now. Xiao Chen watched everyone, I didn't accept it, I said: "The boss, I want to black." "What is black?" The boss wondered. "Black, black is more soy sauce ..." - The whole game is mad # & *% enjoys mode: Enjoying Yuan model high efficiently supports a large number of fine-grained objects. The key to the sharing element can be shared is that its state is stored inside the enjoys, and does not vary with the environment. The status of the regular class can be shared from the conventional classes, and the state that cannot be shared from the class is removed from the class. When the client gets an object from the factory, the factory will check if it has this object, and if it is, it will return to the customer directly, and no new instance is created. The enjoyment mode greatly reduces the number of objects in memory. Those spicy, Sichuan flavors are all enjoyed, there are many beef noodles, but the taste is so much. Later, we played basketball and went to the store. I haven't waited for Xiao Chen, the boss said: "This classmate, you are a black beef noodles." - Xiao Chen ... "

11, = facade = Also started with the X-based season, the specific time and place have to rely on this captain to get it, good, no problem! A call for the X-series basketball team captain: "3:00 am on Saturday, we have seen it high."

Facade mode: The facade mode provides a high-level interface that makes the subsystem easier to use, it separates the client and some subsystems to improve the independence and portability of the subsystem. The X-series basketball team captain is a Facade, through him, lest I am going to notify them by a team member (subsystem).

12, = Bridge = I am a student, but in the basketball team, I am a player, then what do you say, Super Saiyan? Ha ha.

Bridge mode: Differentialization of abstraction and implementation make the two can change independently, that is, the strong correlation between them becomes weakly associated, that is, refers to the abstraction and implementation of a software system. The combination / polymeric relationship is used instead of inheritance, so that both can change independently. Haha, thanks to this model, or I really don't know what to call me, 嘻嘻.

== behavioral mode ==

13, = Strategy = There are many tactics in football, for example, in general, 442, can use 451, weakened teams can use 343. Of course, there are also basketballs. For example, you can choose to make a center, or far vote, of course, we usually use the most useful, haha.

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.

14, = Template Method = Different basketball classes have different teachers, but they are the same, generally divided into drums, pass, shoot, lay baskets, and estimates the teaching of sports teachers. The template is like this. How can I teach in the specific municipality, how to teach it in the back, according to different teachers. Template Method: Template Method Preparations an abstract class to achieve partial logic in the form of a specific method and a concrete structure, then declare some abstract methods to force subclasses to achieve 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.

15, = observer = "Take the basketball this afternoon." - a "Good, call me." -B "is also called me." -C "also has me." - D ... our class Chambel, huh, huh, huh.

Observer mode: The observer mode makes the observer and the coupling between the observer, and the observer will issue notices to all registered observes. When A is going to play basketball, it will notify B, C, D ...

16, = iTerator = Big basketball lesson, sports teacher wants to be famous: "Xiao Wang (Sports Committee), how many people do you have to class?" Xiao Wang: " , 4, ... "

Iterative Submount: Iterative Submount can sequentially access a gathering element without exposing the gathered internal appearance. 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. Xiao Wang is really smart, you don't have to query anyone know how many people have.

17, = CHAIN ​​of Responsibleity = Now the Lakers attack, Pedon handed the ball to Malong, Malone passed to O'Neill, O'Neill's rebate, the Lake people added 2 points.

Responsible Chain Mode: In the liability chain mode, many objects are connected by each object to the reference to which they will 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. In fact, the ball just now, O'Neill can pass to Kobe to come to an air relay, the wind bus, then Perfect!

18, = Command = a key game last second by the three points determined to win, but it can be tired. "Come to the glass." I heard, my classmate A is called a mm, MM, I poured a glass of water. "Be sour." I heard, my classmate A immediately called the mm to give me a hammer. "I really want to take a shower." I really listen ... ", I am not that, wow, wow ... ^ ¥ & #."

Command mode: Command mode encapsulates 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. If you know how to do that command, you won't say that sentence, 呜呜 ... 19, = memento = a NBA game, you can automatically switch, but to change the registration, of course, first find the key Value "Final", right button, exported to final.reg, then you can change it, in case it is wrong, you can also double click Final.reg, huh.

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 status of an object without damaging the package, and separated from the object, stored, so that this object is restored to the stored state.

20, State Today, playing is really hard, shooting old. Suddenly, one mm came over ... Ah -, the third order of the super-race, transform! After turning into the incident, there is different, and there are two people who have easy-to-hand, and they will take a hand in three people's pentals. (Oh, you will blow)

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. The status mode requires a subclass of a status class for each system possible. When the status of the system changes, the system actually changes the selected subclass. This mode can be considered when an object behavior relies on its state. When MM didn't come, the status is poor, causing the shot committee.靓 MM is coming, the status is beautiful, it is to play, haha.

21, = Visitor = The next semester basketball class has been replaced by a teacher. Of course, he is completely unfamiliar, so the first class, he took a roster to find the sports committee Xiao Wang: "How is Xiao Chen technology?" - "Generally "" Little Luo? "-" OK, but can't go it. "" What about? "-" He ah ... ", etc., I have a cough. "How did he?" - "He, he is not bad!" Haha. "It is a shot old commission!" - Ah, you are small, play me.

Visitor mode: The purpose of the visitor mode is to encapsulate some operations that apply to some data structural elements, making it easy to add new operations, once these operations need to be modified, the data structure accepting this operation can remain unchanged. For example, the teacher can also get the height of each of us through Xiao Wang. The visitor pattern can accepted a member class (more than the generation) that belongs to several classs, but it is difficult to add a new node. If we come to a new classmate, small The king will not use it.

22, = interpreter = I want to know how to play a cool fake action, I have the classic highlights of And1 here, according to the above practice.

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. 23, = mediator = 俺 A high school classmate small D to me, of course, playing is essential. Calling Xiao Wang goes out of K others, but small D and Xiao Wang are not criticized, so there is almost no cooperation, and the result is 5: 0 in CAI. I have to "rest" in the end. Xiao Wang: "Telling your classmates less, more pass." - "OK." I passed the opinion to small D. Small D: "Your classmate is defensive, you have to keep people, don't focus on the ball." - "No problem." I passed the opinion to Xiao Wang again.

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. Sure enough, I rely on me this Mediator, we also have an opponent's egg. Haha!

Reference: << Chasing MM and Design Model >> << Java and Mode >> 2. From: http://blog.9cbs.net/yuanqingfei/articles/38633.aspx creation mode 1, Factory-Talent Market: Which person is to be, I will find which talent, low efficiency, now there is a talent market, we just go directly to the talent market to pick a better; - How do people change to a headhunting company? 2, Builder-Production Water: Previously, the artificial workshop-style artificial single production part then step by step, it is better than the industrial revolution, and now it is replaced by the production line. To make Toyota car, the construction of the car is first set, such as a car, steering wheel, and engine. Then use this construction standard to produce Toyota car's tires, steering wheel, engine. Then make the assembly. Finally, you will get Toyota Automobile; 3, Singleton - Unique: It was previously a trademark full day, the same trademark is inevitable to cause infringement. After the trademark protection law, it is guaranteed that the same trademark will not produce the same trademark will not produce the same company; ? 4, Adapter - the private person of the audience, Cheng Yi's public: Wudang sent Zhang Sanfeng will Tai Chi, Shaolin sent a wise master of the Master, if they both became my master, I will be both Tai Chi, will The King Kong is just ahead; - can't, so do you tell you two major masters who are taking the Shaolang Wudang? 5, Decorator - Qingzhong is more than blue: Wudang Zhang Sanfeng will Tai Chi, is my master, he teaches me Tai Chi, but I will point to Mongolian fell, Zhang Sanfeng will not. So I became the implementation of the Decorator mode; - I could be too big, you can be too much than Zhang Sanfeng, this is not called the decoration. :) 6, Bridge- White Malaysia: The color of the horse has black and white, the gender of the horse has a male and female. We said that "This is the horse" too abstract, saying "This is a black mission" is also a dead plate, only combined with gender and horses, "this is (black or white) (male or female) horse" It seems flexible and elegant, so Bridge mode is essential. - How can I say this? It is really impossible to imagine that the interface is such a statement. 7, Composite - big family: Son again and grandchildren, Sun Yicon, child grandson, endless, organize many people to organize a large family in life is the realization of this model; - Can I change? What is the family spectrum? 8, FACADE - Search: High school graduation needs to read junior high school and high school, doctoral needs to read junior high school and high schools, so the state will become a nine-year compulsory education in junior high school and high school; - High school is also in the 9-year-impulse education? What is the revision to collect money to ensure the Director of Admissions Office attended University? He is responsible for opening other internal links. 9, Flyweight - One Yiyi: Recognize three thousand Chinese characters, you can cope with your daily reading and writing, you can see the importance of this Chinese word library in the head; 10, proxy-sputum, listening to the spirits: It is like the four major cuoders in the Qing dynasty in the Qing dynasty, many rights are not in the emperor's hand, must go to the minister; - how to change to military machines? I only deal with some regular things, and important things are still reported to the emperor.

11, Chain of Responsibleity - Renting: In the past, in order to find a house, it can be used everywhere, the efficiency is low and the good listings are not found. Now there is a housing intermediary, so I will ask the house intermediary to rent a house request. The intermediary provides a suitable listing, satisfaction, no longer requests, dissatisfaction continues to see the room until satisfaction; - this can be no chain. 12, Command - Borrowing Kill: I used to kill who will kill, but after a period of time, I have a great revenge, so I have a fake hand, and the relationship between others will make my own purpose; - If this sentence It is very embarrassing that a knife is said. 13, interpreter - Classical Chinese Note: A paragraph of classical Chinese, translating it into white traine; - change to eight shares? 14, iTerator - rush to kill: a search, never let it fall; - It is better to change what to copy, it will take it. 15, MEMENTO - is a blessing: How much do I have, how much you are; - It is difficult to make a different blessings. 16, State - Entering Freedom: If a door can enter, if there are many people entering and exiting the out and makes a mess, there is now a security to restrict its entry, so people can enter and do a normative; - change to What is the traffic light? 17, Strategy - Longji doctor: If a person can have a variety of symptoms, but after long-term exploration, you can summarize several kinds of colds, lung diseases, and hepatitis; - really can't come up with similar places, then say 19 Template Method - Theory is not necessarily practiced: the coach's students will swim, as for the coach will not be tight; - but coach and students are not inheritance. 20. Visitor - Sin of the rule of law: Because Zhang San murder is going to die, Li Zi steals to be fined. This is bound to formulate a penalty system, so it is necessary to make a law to write a murder, afire, stealing, and other penalties. It must be small after passing. Someone in the future is no matter who is, the punishment according to the total regulations is, this is the whole process of visiting the birth of the visitors; - did not mean at all. Chain of Responsible: For example, you are a software company developer, your direct boss is the development team leader, the leader is the department manager, the department manager is the general manager. You have three requirements now: The first is some of the modules of the project, and then the second is to rise. The third one wants to buy a house from the company's interest rate loan. You tell the leaders of these three requirements, and the team leader can only help you solve the first request, and then he will tell his 2nd, 3 requirements to his next: "Node" department manager, department manager can help you solve the 2 requirements, then put the third request to the general manager ..... I want to be like this. Supplement STRATEGY mode: Can be such a bit: a black helper has a left right arm, the first look must kill someone, his lefton claims ambush in the evening, then kills it; the right arm is sneaked in advance to kill the poison . The lead thinks about how to do it for two years, in the last level (running time) decided to adopt the left left method ... No matter which method, it has reached the same purpose, you can extract the interface: Killer (the brothers), this The interface has a unique method: Kill (Man Man). The right arm is the class of the Killer interface, respectively. First continue to talk about my understanding of Iterator mode: Assuming in the war age, our party is involved in the underground party members of the enemy to be seen as all members in a data structure.

转载请注明原文地址:https://www.9cbs.com/read-16756.html

New Post(0)