Basic object-oriented design principles

Basic object-oriented design principles

Single Responsibility Principle (SRP) : It stipulates that a class should have only one reason for change. The so-called responsibility refers to the reason for class changes. If a class has more than one motivation to be changed, then this class has more than one responsibility. The single responsibility principle means that a class or module should have one and only one reason for change.

Open and Close Principle (OCP) : The software entity should be open to extension and closed to modification. The open and close principle is the core principle of the design principle. Other design principles are the expression and supplement of the open and close principle. The method to realize the open and close principle is abstraction.

Liskov Substitution Principle (LSP) : Wherever a parent class appears, it can be replaced by its subclass. Single responsibility principle: A class should only do things related to one responsibility, and don't put too much business in one class.

Interface Isolation Principle (ISP) : It is better to use a dedicated interface than to use a unified interface, which facilitates the division of labor. When implementing an interface, you should not see methods you don't care about.

Dependency Inversion Principle (DIP) : Facing abstract programming, not concrete programming.

The principle of Dimit (LOD) : The interaction between software entities should be minimal, do not talk to strangers, the caller only cares about the methods he needs to use.

Combination or aggregation reuse principle (CRP) : Use aggregation or combination more to achieve code reuse, and less use inheritance reuse.

Guess you like

Origin blog.csdn.net/weixin_49092628/article/details/110086442