6 Major design principles
1. Single responsibility Principle (SRP): There should be and only one cause for class changes. Interface must be a single responsibility, the design of the class as far as possible only one cause of change.
2. Richter replacement principle (LSP): All references to base classes must be able to transparently use objects of their subclasses. As long as the parent class can appear where the subclass can appear, and the substitution of subclasses will not produce any errors or exceptions, but the reverse is not, where there are subclasses, the parent may not be able to adapt.
- Subclasses must fully implement the methods of the parent class
- Subclasses can have their own personalities.
- input Parameters can be magnified when overriding or implementing a method of a parent class (the precondition of a method in a subclass must be the same or looser than the precondition of a method overridden in a superclass)
- The output can be scaled down when overriding or implementing a method of the parent class (the return value of a method of a parent class is a type T, and the return value of the same method (overloaded or overridden) of the subclass is S, then the Richter substitution principle requires s to be less than or equal to T.
3. Dependency inversion principle (DIP):
- The high-level module should not rely on the bottom low-layer module, both should rely on its abstraction;
- Abstraction should not depend on details;
- Detail should be dependent on abstraction.
The dependency of a PS object is passed in three ways
One, the constructor passes the dependent object public A (b) {a.b = b}
Second, setter method pass dependent object public Setb (b) {a.b = B}
Iii. Interface Declaration dependent objects
4. Interface Isolation principle
———————— to Be Continued ————————————
Design Patterns--The Zen reading notes of design patterns