Summary of design patterns Application Instances

Source: Internet
Author: User

1. Singleton Mode
Application Example: 1. one Party can only have one chairman. 2. windows is multi-process and multi-thread. When operating a file, it is inevitable that multiple processes or threads operate on a file simultaneously, therefore, all files must be processed through a unique instance. 3. Some device managers are often designed as Singleton mode. For example, if a computer has two printers, the same file cannot be printed on two printers during output.
2. Factory Model
Application Example: 1. you need a car, you can pick up the goods directly from the factory, instead of worrying about how the car was made, and the specific implementation of the car. for Hibernate databases, you only need to change the dialect and driver.
3. Abstract Factory
Application Example: after work, there must be two or more clothes for some Parties, such as business clothes (Complete Sets, a series of specific products) and fashion clothes (Complete Sets, A series of specific products), even for a family, there may be Business Women's Wear, business men's wear, fashion Women's Wear, fashion men's wear, these are also complete sets, that is, a series of specific products. let's assume that there is a situation (in reality, it doesn't exist; otherwise, it won't be possible to enter communism, but it is helpful to illustrate the abstract factory model). In your home, a wardrobe (specific factory) you can only store a certain type of clothing (set, a series of specific products). Each time you take this set of clothes, you will naturally need to take them out of this wardrobe. with OO, we can understand that all wardrobes (specific factories) are wardrobes (Abstract factories, each complete set of clothes includes a specific coat (a specific product) and trousers (a specific product). These specific jackets are actually jackets (Abstract products ), the specific trousers are also trousers (another abstract product ).
4. Builder Mode
Application Example: 1. Go to KFC, hamburger, cola, french fries, fried chicken wings and so on, and its combination is constantly changing, generate the so-called "package" 2. StringBuilder in JAVA
5. prototype mode
Application Example: 1. Cell Division 2. Object clone () method in JAVA
6. Adapter Mode
Application Example: 1. US Electric Appliance 110 V, China 220 V, there is an adapter to convert 110V to 220 V 2. java jdk 1.1 provides the Enumeration interface, while 1.2 provides the Iterator interface. To use JDK 1.2, You need to convert the Enumeration interface of the previous system to the Iterator interface, in this case, the adapter mode is required. run WINDOWS program on LINUX 4. jdbc in java
7. Combination Mode
Application Example: 1. arithmetic expressions include operands, operators, and other operands. Another operator can also be an operation tree, operator, and another operand. in java awt and SWING, for Button and Checkbox, It is leaf, and Container is branch.
8. decoration Mode
Application Example: 1. sun Wukong changed 72 times. When he became a "Temple", he was still a monkey, but he had the function of a temple. A painting can be mounted to a wall, whether it is a picture or a frame, but it is usually a frame that is actually mounted to a wall. Before hanging on the wall, the painting can be covered with glass and mounted into the frame. At this time, the painting, glass and frame form an object.
9. Proxy Mode
Application Example: 1. shortcuts in windows 2. sun Wukong changed the result when he tried to find Gao Cuilan. He could understand it as follows: he abstracted the appearance of Gao Cuilan and Sun Wukong both implemented this interface, when Zhu Bajie visited Gao Cuilan, he could not see that this was Sun Wukong, So Sun Wukong was a high Cuilan agent. 3. If you do not have to buy a train ticket at the railway station, you can also go to the sales representative site. 4. A check or bank deposit form is the agent of funds in your account. Check is used to replace cash in market transactions and control the funds on the issuer's account. 5. spring aop
10. Metadata Mode
Application Instance: 1. String in JAVA. If yes, return. If no, create a String and save it in the String cache pool. 2. Database Data Pool
11. Facade Mode
Application Example: 1. when you go to the hospital to see a doctor, you may need to go to registration, outpatient service, price assignment, and take medicine, which makes the patient or the patient's family feel complicated. If there is a reception staff, only the reception staff can handle the problem, 2. JAVA three-tier development model
12. Bridging Mode
Application Example: 1. Pig Bajie from Marshal tianpeng reincarnation to pig, the reincarnation mechanism divides the world into two levels: soul and body, the former is equivalent to abstraction, the latter is equivalent to implementation. Through the assignment of functions, a creature calls the function of a physical object so that the creature can dynamically choose 2. The switch on the wall can be seen on its own. How can we implement the switch in it?
13. Rule Mode
Application Example: 1. Zhuge Liang's tips. Every tip is a strategy. 2. Travel mode, choosing to ride a bicycle or take a taxi is a strategy. 3. LayoutManager in JAVA AWT
14. template method mode
Application Example: 1. When building a house, the foundation, cabling, and water pipes are the same. Only after the building is in the later stage can there be a gap between the closet and the fence. 2. It is difficult for the Bodhisattva to set up 81 in the Travel Notes to the west, this is a top-level logical skeleton. 3. Support for Hibernate in Spirng. It encapsulates Some preset methods, such as starting transactions, obtaining sessions, and closing sessions, the programmer can save the code without repeating the code that has already been standardized by dropping an entity.
15. Observer Mode
Application Example: 1. during the auction, the auctioneer observes the highest price, and then notifies other contestants of the bidding price. 2. In the Travel Notes to the west, Wukong requests the Bodhisattva to take down the red child, And the Bodhisattva spills a water to attract an old tortoise, the tortoise is the observer. He observes the water sprinkling action of the Bodhisattva.
16. iterator Mode
Application Example: iterator in JAVA
17. Responsibility Chain Model
Application Example: 1. "drumming and spreading" in A Dream of Red Mansions 2. Event bubbling in JS 3. Apache Tomcat processing in java web, Struts2 interceptor, and jsp servlet Filte
18. Command mode
Application Example: there is only one ActionServlet core controller of action in struts 1, which is equivalent to Invoker. The classes at the model layer have different model classes with different applications, which is equivalent to the specific Command
19. Memorandum Mode
Application instance: 1. Regret 2. archive during game preparation 3. ctri + z 4 in Windows 4. Retreat in IE 4. Database Transaction Management 5. SESSION and COOKIE in WEB 6. Participants in Sun Wukong tree push, then I turned to Guanyin for help. Guanyin sprinkled several drops of water, and the ninth affiliated post. Among them, Sun Wukong was the initiator, ginseng tree was the specific object (Originator), and those drips were Memento ), guanyin is the owner role (Caretaker)
20. Status Mode
Application Example: 1. When playing basketball, athletes can be in normal or abnormal status. 2. In Zeng Hou and Yi, 'clock is an abstract interface ', 'zhong a' and so on are specific States, and 'zeng Hou and Yi chimer' are specific environments (Context)
21. Visitor Mode
Application Example: you are visiting a friend's house. You are a visitor and a friend accepts your visit. You use a friend's description to make a judgment on the friend's description. This is the visitor's mode.
22. interpreter Mode
Application Example: compiler, computation expression Calculation
23. intermediary Mode
Application Examples: 1. China's accession to the WTO was previously a process of mutual trade and complex structure. Now it is a process of mutual trade through the WTO. 2. airport scheduling system. 3. MVC framework, C (Controller) is the intermediary between M and V.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.