Master Design Patterns

Source: Internet
Author: User
The side dishes of the IT workplace often have these questions:

Why a similar function, Daniel will be done in a moment, and then leisurely tasting afternoon tea shopping Taobao, and their own overtime to get to the dawn can not finish.

Why the user proposed changes in demand, Daniel just smart to knock on the keyboard, change the configuration, and their own code changed and changed, deleted and built, almost fainted, the last can only overturn.

Why Daniel finished the program test on the line, almost perfect operation, the user is airtight, and their own program bugs, change a good one but leads to another, gourd Dipper float, nearly collapse.

Why is the same programmer, Daniel Wages 1W, and he can only take a mere 3K.

Daniel obviously knows some secret which is not known by the vegetable, what is the secret?

The secret is the design pattern. Design Patterns are a set of repeated use, most people know, through the classification of purpose, code design experience Summary. Design patterns are used in order to reuse code, make code easier for others to understand, and ensure code reliability. Design patterns make coding truly engineering, design patterns are the cornerstone of software engineering, like a block of bricks and stones in a building. Only if you are proficient in the design pattern, can you say that you really understand software engineering. It can be said that design patterns are one of the necessary skills for every architect. As an object-oriented design programmer, only proficient in the design pattern, in order to complete their own value from 3K to 1W Leap, in order to get rid of the fate of the slave code, to become a real software engineer.

Referring to design patterns, we have to thank Gof (Gang of Four, Group of Four), their 1995 book "Design Pattern", the first time the design model to the theoretical height, and to standardize. 23 basic design Patterns are summed up in the book. These 23 design patterns cover almost all the solutions to the problem in the object-oriented design process. The 23 design patterns mentioned in the book are:

1. Single case mode 2. Factory method mode 3. Abstract Factory mode 4. Template method mode 5. Builder Mode 6. Agent Mode 7. Prototype mode 8. Intermediary mode
9. Command mode 10. Mode of responsibility Chain 11. Decoration Mode 12. Mode 13. Adapter Mode 14. Iterator mode 15. Combined mode 16. Observer mode
17. Facade Mode 18. Memo mode 19. Visitor mode 20. Status mode 21. Interpreter Mode
22. Mode 23. Mode of bridge

So how many design patterns come from. "I Ching," There are clouds: "Easy to have Tai Chi, is the birth of two instruments, two instruments born four like, four-like gossip", meaning that the world all things have origins. The origin of design pattern is object-oriented programming idea, is the essence of object-oriented design-abstraction. Object-oriented abstraction is realized by classes and objects, and three important mechanisms are created: encapsulation, inheritance, polymorphism. It is these three mechanisms that derive a variety of design patterns. In the development process of object-oriented software design, the new design pattern is still appearing in addition to the 23 design pattern mentioned in "design pattern".

From process-oriented to object-oriented is the greatest step since the birth of software design, object-oriented programming successfully solves the problem of low efficiency facing process software programming, and completely changes people's programming thinking, which opens a new chapter for software design. However, to achieve object-oriented design, completely rid of process-oriented design thinking, and not only the use of an object-oriented programming language can be achieved. With object-oriented design, you can design excellent software, and you can also design bad software. Only by following some specific principles can we design reusable software with high flexibility.

In the use of object-oriented ideas for software design, there are 6 principles to follow:

1. Principle of sole responsibility (single responsibility principle)
2. Richter replacement principle (Liskov substitution principle)
3. Dependency inversion principle (dependence inversion principle)
4. Interface Isolation principle (Interface segregation principle)
5. Dimitri (Law of Demeter)
6. Opening and closing principle (Open close principle)

In the process of software design, as long as we try to follow the above six design principles, the design of the software will be a good software, it must be strong enough, stable enough, and with great flexibility to meet the need to change at any time and other factors. When we fully understand the meaning of these six principles, the vegetable dishes have completed the transformation towards Daniel.

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.