I. Design Principles
1. Dependency inversion principle (DIP)
High-level modules (stability) should not depend on low-level modules (changes), both of which should depend on abstraction.
Abstract (stable) should not depend on implementation details (changes), and implementation details should depend on abstraction.
2. Open and closed principle (OCP)
Class modules should be extensible, but cannot be modified; open to extensions and closed to changes
3 single responsibility principle (SRP)
A class should have only one reason for its change.
4 liskov replacement principle (LSP)
Subclass must be able to replace their base classes
5 interface isolation principle (ISP)
Customers should not be forcedProgramDepending on the methods they do not need.
2. Object-oriented Design Principles
1. Interface Programming, not implementation programming
The customer does not need to know the specific type of the used object, but only needs to know that the object has the interface that the customer expects.
2. Object combination is preferred, rather than class inheritance.
Class inheritance is usually "white box reuse", and the object combination is usually "black box reuse ". Inheritance damages encapsulation to some extent, and the Child class parent class has a high Coupling Degree. Object combination only requires that the combined object has a well-defined interface, and the coupling degree is low.
3. encapsulation changes
The encapsulation is used to create the demarcation layer between objects, so that the designer can modify the interface on one side of the demarcation layer without affecting the other side, so as to implement loose coupling between layers.