Six design principles of open IOS design patterns - Closed Principle (OCP, Open-Close Principle)

definition

  A software entity ( such as classes, modules, functions ) should be open for extension but closed for modification.

Interpretation of the definition

  When the project development, we can not expect the demand is determined not to change, in most cases, needs are changing. So how to deal with the situation changing needs? This is open - closed principle to talk about.

  Open - thought closed principle is to design, try to make the design of the class after doing no longer be modified if there is a new demand by adding new ways to meet the class, rather than to modify an existing class ( the code ) . So in the actual project development, whether it can be absolutely closed for modification of it? The answer is usually no. If so, then we are required prior to development, to find out the change point, and then construct an abstract point for change, isolate these changes. Thus, to achieve the opening and closing key principle is abstract.

advantage

  • Flexibility, can be realized by expanding the extension of a functional module, no need to modify the internal code.
  • Stability, the performance of the basic functions in the class can not be modified, so that the degree of destruction is greatly reduced.

to sum up

  For the six design principles of design patterns, single responsibility principle main job description to a single class; Richter substitution principle emphasized not to destroy the inheritance hierarchy; Dependency Inversion Principle described to be oriented programming interface; the interface isolation interface design principles to explain the time to streamline; Demeter tells us to reduce the coupling; opening and closing principle is about to open for extension, but closed for modification.

  Six design principles and not very clear boundaries, when we follow a certain design principles may also comply with the other design principles. Design principle is the basis behind want to talk about design patterns, so before this series about design patterns, design principles to understand said.

  Back to Contents

Reproduced in: https: //www.cnblogs.com/eagle927183/p/3455180.html

Guess you like

Origin blog.csdn.net/weixin_34216196/article/details/93725186