1 Principle of opening/closing (OCP,The Open-Closed Principle)
In principle, all software modules should be scalable, but cannot be modified. The key to following this principle is abstraction. We are writing
Module, whether it is a class or a component, you should seriously consider its real functions, its dependence on other modules, input and output
And so on. Separate the variable part (for example, using an interface or external configuration) and encapsulate the unchanged part. These unchanged parts are
Module. Here, we need to explain how to define the unchanged part when encapsulating the unchanged part. In mathematics, when we
When talking about the invariant, it is always necessary to specify under what changes it is. Otherwise it makes no sense, because the invariant under a change is very
It may not be a constant in another change. Therefore, when we define the unchanged part, we must first clarify its scope of change. However
In software development, it is difficult to know these changes accurately in advance, often based on experience or industry knowledge. So how much is this principle?
Less subjective, more like a general outline than a rigid legal provision.Martin FowlerBooksAnalysis PatternsExplained some implementations
Experience. For more information, see. The following principles describe how to arrange dependencies so that the modules are well closed, reusable, and
Maintainability.
2. Dependency reverse principle (DIP,
<