The open-closed principle (open-closed principle) is the cornerstone of object-oriented reusable design (Object Oriented Design or OOD. Other design principles (the Lee principle of substitution, the principle of dependency inversion, the principle of synthesis/aggregation reuse, the principle of Demeter, and the principle of interface isolation) are the means and tools for implementing the "open-closed" principle.
Definition of the "Open-Close" Principle
Definition: A software entity should be open to extensions and closed to modifications.
(Software entities shocould be open for extension, but closed for modification ).
When designing a software system module, the module should be extended without being modified, or, you can change the behavior of this module without having to modify the original code.
Advantages of a system that meets the "On-Off" Principle
1) by extending existing software systems, new behaviors can be provided to meet new demands for software and make the software systems in change adaptive and flexible.
2) the existing software modules, especially the most important abstract layer modules, cannot be modified any more, which makes the software system in change stable and continuous.
A system with two advantages is a system that achieves reuse at a high level and is easy to maintain.
Implementation of the "Open-Close" principle -- Abstraction
Object-Oriented programming languages can use abstract methods to define an abstract design that will not be changed for the system as the abstraction layer of the system. This abstraction layer covers all future extensions, so it will not change in any situation. In this way, the abstraction layer of the system remains unchanged, so that the second point of the open and closed principle is met: Disable the modification.
One or more classes exported from the abstraction layer can change the system's behavior, because the system design is open to expansion and thus satisfies the first point of the open and closed principle: open to expansion.
In the SCA framework, the application of the open/closed principle can be seen in both commonj and SPI; composite and component.