Design mode metaphor

zhaozj2021-02-16  72

The post of the landlord, in the heart, I passed the GOF DP again, I feel that this way to learn DP is very preferable, and I don't stand the thoughts. Some of the content inside, feel that some places are not very appropriate, commented on the reference: Create mode 1, Factory-Talent Market: Which talent is to be in the past, which person is looking for, low efficiency, now there is a talent market, we only need Going directly to the talent market to pick a good; - How does the people exchanged into 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 - a long-term illness:

19. Template method - Theory is not necessarily practiced: the coach 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 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.

Let me talk about my understanding of Iterator mode:

Assuming in the war age, our party to enter the underground party members inside the enemy are seen as all members in a data structure. At this time, a traitor was in the enemy's forced confession, the traitor became the Iterator of the data structure. He may have all the confessions (such as vector Elements), maybe some concealment, that is, I often say Iterator's filtering, in short this Iterator has a lot of freedom to determine how many, how to tell, etc. . . . Tainy_zhang's Iterator mode is very interesting, add a code:

// During the revolutionary war during the revolutionary war ... Iterator traitor = underground party. Generate a traitor (); while (! Traitor. Reference ()) {特. Arrest (traitor. Reserve ()); traitor. Next ();

Package china.war.revolution;

Public interface iterator {public underground party member recovery (); public boolean recovery (); public void next ();

Public Class underground party {private vector underground party members;

Public underground party () {...}

PUBLIC ITERATOR generated traitor () {...};

The ADAPTER mode of the landlord is not pair, and Adapter is a class that turns an incompatible class (method name, parameter does not meet the current client), such as:

My son just wants to eat steamed dumplings, and mother will only do water dumplings, now Dad comes to be adapters:

Definition: Class mother {public dumplings ();} Class Son {public void eat (steamed dumplings jiaozi);

Son. Eating () the parameters of the method and mother. Different to the return, so you have an adapter:

Class adapter {private mother mother;

Public Adapter (Mother Mother) {this. Mom = Mom;

Public steamed dumplings () {Return Dry (mother. Do ()); // But Dad will not make dumplings, can only make moms do the mother};

Now my son can eat steamed dumplings: Mother Mom = New Mother (); Son Son = New Son (); Adapter Dad = New Adapter (Mom); Son. Eating (Dad. Do ()); //. .

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

New Post(0)