The six design principles of Zen design pattern-open and closed principle

Source: Internet
Author: User

Opening and closing principle

One: the definition of open and closed principle
---> A software entity such as classes, modules, and functions should be open to extensions and closed for modification.
---> We do one thing, or choose a direction, generally need to go through three steps: What is what--, why--why, how--how to do (abbreviation 3W principle, how to take the last W)
---> For the opening and closing principle, we also use these three steps to analyze, that is, what is the open and close principle, why use open and close principle, how to use the open and closed principle?


Second: How to use the open and closed principle
---> Abstract constraints.
(1) Define the interface and, if the business changes, override the methods in the class without modifying the original code. is to open the extension and close the modification.

---> Meta data (Metadata) control module behavior
(1) programming is a very hard and tiring life, how can we relieve our stress? The answer is to try to use metadata to control the behavior of the program and reduce duplication of development. What is metadata? The data used to describe the environment and data, in layman terms, are configuration parameters that can be obtained from a file or from a database.


-----> Develop Project Charter
(1) Norm-setting, unified style programming
-----> Package Changes
(1) The package of changes contains two meanings: first, the same change is encapsulated in an interface or abstract class. Second: The different changes are encapsulated in different interfaces or abstract classes, and there should not be two different changes appearing in the same interface or abstract class.


III: Best Practices
----> Software Design the biggest challenge is to respond to changes in demand, but the complexity of demand changes is unpredictable. 6 design principles and 23 design patterns to "encapsulate" future changes.

----> Open and Close principle is only a principle.
(1) The opening and closing principle is only the spirit slogan, realizes embraces the change the method is very many, does not limit these 6 big design principle, but follows the 6 big design principle to be able to deal with most changes basically.
(2) The principle of opening and closing, is the purpose of the other five Principles. The other five principles are the concrete realization of the opening and closing principle














































The six design principles of Zen design pattern-open and closed principle

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.