Five principles of design patterns-SOLID principles

The SOLID principles in the design pattern are the single principle, the opening and closing principle, the Richter substitution principle, the interface isolation principle, and the dependency inversion principle.

Following the five principles can make the program more robust in solving tight coupling.

SICKLE Single responsibility principle
OCP Open and closed principle
LSP Richter substitution principle
ISP Interface isolation principle
DIP Dependence inversion principle

 Single responsibility principle

Refers to a class or a method that only does one thing. If a class undertakes too many responsibilities, it is equivalent to coupling these responsibilities together, and the change of one responsibility may inhibit or weaken the ability of this class to perform other responsibilities.

Open and closed principle

Open for extension, closed for modification. It can be extended (extension), cannot be modified (modification), a class should not be modified after it is independent, but to adapt to new requirements in an extended way.

Richter substitution principle

All occurrences of base classes can be replaced with derived classes without program error. Subclasses can extend the functions of the parent class, but cannot change the original functions of the parent class.

Interface isolation principle

The class should not rely on unneeded interfaces. The dependency of one class on another should be based on the smallest interface.

Dependence inversion principle

It means that high-level modules should not rely on low-level modules, but on abstraction. Abstraction cannot depend on details, and details must depend on abstraction.

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/feikillyou/article/details/111063311