- Single Responsibility Principle (SRP)
- Open-Close principle (OCP)
- Replacement principle (LSP)
- Dependency inversion principle (DIP)
- Interface isolation principle (ISP)
Simple understanding
Single responsibility: the role of a class should be focused on one aspect. The reason for changing this category is only this change.
Open-closed principle: when designing a class, consider that the class may change in the future. In order to eliminate the changes to the class, the class should be open to class extension during design. The basic method is to abstract the objects involved in a specific class by using abstraction, so as to reduce the dependency of a small class on a specific object.
Replacement principle: the inheritance of OO allows child classes to replace the use of parent classes. "Is a" of behavior is a "of subclass and parent class ". Replacement of child classes cannot undermine the correctness of the original prediction of parent behaviors.
Dependency inversion principle: customers (class users) cannot rely on the objects (classes) that provide services ). The specific method is to abstract the objects that provide services. This is the same as that in the real world. You may not go to a restaurant to eat. Different restaurants can offer your favorite dishes.
Interface isolation: for customers in different aspects, the abstraction of objects should be separated. Do not provide customers with behaviors and attributes that do not need to be known to them. This prevents customers from introducing unnecessary burdens when using objects.