Solid is an abbreviation for several important coding principles
Srp:the Single Responsibility Principle sole responsibility principle
Ocp:the Open Closed Principle opening and closing principle
lsp:the Liskov Substitution Principle Richter Replacement principle
Ld:the Law of Demeter Dimitri
Isp:the Interface Segregation Principle Interface separation principle
Dip:the Dependency Inversion Principle dependency inversion principle
One, the single principle of responsibility
There is only one reason to change the class. That is, each class does only one type of responsibility, and when the class has multiple responsibilities, the class is decomposed.
two, opening and closing principle
Open for extensions, close for modifications.
The open and closed principle is the most basic design principle in object-oriented design, and also the most vague principle of definition. The opening and closing principle can be summed up as follows: Using abstract component framework to realize the extension details.
The other 5 principles and the 23 design pattern are designed to follow the open and closed principle. The principle of single responsibility tells us that the realization of the class to be a single duty; the Richter substitution principle tells us not to break the inheritance system; The dependency inversion principle tells us to interface programming, and the interface isolation principle tells us to simplify the design of the interface, and the Dimitri Law tells us to reduce the coupling.
Three, the Richter replacement principle
Subclasses try not to overwrite the methods of the parent class.
Subclasses can extend the functionality of the parent class, but cannot change the original functionality of the parent class.
The ① subclass can implement an abstract method of the parent class, but cannot overwrite the non-abstract method of the parent class.
The unique method can be added to the ② subclass.
③ when a method of a subclass overloads a method of the parent class, the method's post condition (that is, the method's return value) is stricter than the parent class.
④ when a method of a subclass implements an abstract method of the parent class, the post condition of the method (that is, the return value of the method) is stricter than the parent class.
Four, the law of Dimitri
Also known as the least known principle, an object should keep a minimal understanding of other objects. Is that a class knows as little as possible about the classes it relies on.
Five, interface separation principle
Using multiple specialized interfaces is better than using a single total interface.
VI, dependency inversion principle
High-level modules should not be dependent on the underlying modules, which should all depend on abstraction. Abstractions should not be dependent on detail, and detail should be dependent on abstraction.