One of the No nonsense C # Design Patterns: Opening

Source: Internet
Author: User

What is a design pattern?

What is Shaolin? Shaolin is the Shaolin monk after a long summary, a set of martial arts routines. There is a book called the Shaolin Method of martial arts cheats, the above records of this boxing method applicable to the crowd, play routines and after the results. Although the design pattern is recorded in the design pattern book, it is not enough to really master the design pattern by looking at the structure of each pattern and imitating it. Imagine, in real gun combat situation, who will and you in accordance with the Shaolin Law, 1234 of the routine fight it? Play routines can only be used to see, only when you can according to the different scenes of flexibility to say that is to learn the boxing method. There are 36 similar examples, and this is also a pattern, each of which is aimed at different scenarios, and if no matter when it comes to "go for it," then how can this battle be fought?

In short, design patterns need to live to play a role.

What's the use of design patterns?

Design patterns allow you to avoid a rush when you meet the need for change. Design patterns can make your program more maintainable and scalable. Design patterns can make programs more performance-efficient. Of course, the premise is that the correct use of the design pattern, if abused then the design pattern can make the program no one to understand, so that the program slow to death, so that the program can not maintain, add new functionality is equivalent to redo.

Principles of design patterns?

L Single Duty: You do not want to change the CPU because the computer memory is damaged, also should not let a class have many reasons for modification.

L open to expansion, to modify closed: You must not want the computer only a memory slot, add memory to change the motherboard, the program should also be able to do not modify the original program can be extended function.

Richter Replacement: If you buy a DX9 video card that does not support the DX9 feature, then this video card will not work. If the method of the parent class is not implemented in the subclass, it will faint. In the world of programs do not think that birds can fly, first think about what will be the birds.

L-Dependency inversion: Programming for interfaces so that there is no need to modify external code even if the implementation changes. In fact, now the computer hardware, network communication, etc. are consistent with this principle, such as USB interface, PCI-E interface, TCP/IP protocol.

L interface Isolation: Spend 3000 to buy a camera with a photo, listen to MP3 function or spend 1000 to buy a mobile phone, 1000 buy a MP3, 1000 buy a digital camera? Buy the former words mobile phone will be fixed, and not necessarily because can not call and repair, bought the back of three of words even if repair also does not affect other uses, you say to buy Which?

I remember seeing an example that was a lot simpler than fixing the radio. The computer is broken, the replacement of a part can be, because the computer in all parts are based on relatively stable interface, and parts of their own, will not affect each other, the computer itself is a very consistent with the design principles of the product. The radio repair is not so simple, there is no part of the plug-in type, the person who will repair the radio must understand the principle of each part.

The small program is like a radio, it can do so, a total of only one person to do, even if it does not take much time to do it again. Dozens of big projects if you want to change a demand need to involve everyone to modify, then the project will not take much time because of maintenance costs too much, maintenance after too many bugs and scrapped.

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.