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