Review of Design Patterns---Six Principles

Memorization method : SOLID+ Dimit principle

Six Object-Oriented Principles

  • Single Responsibility Principle-SRP

The single responsibility principle is easy to understand, that is, a class should try to do only one thing .

  • Open Close Principle-OCP

The definition of the opening and closing principle is that the objects (classes, modules, functions, etc.) in the software should be open for extension, but closed for modification.
That is, when the requirements change, we need to modify the code. At this time, we should try to expand the original code instead of modifying the original code, because this may cause more problems.

  • Liskov Substitution Principle-LSP

The principle of Li substitution is simply: all references to the base class must be able to transparently use the objects of its subclasses.
The Liskov substitution principle is popularly stated: subclasses can extend the functions of the parent class, but cannot change the original functions of the parent class.

The principle of Liskov substitution and opening and closing is relatively similar. The effect of opening to expansion and closing to modification is achieved through Li substitution.

  • Dependence Inversion Principle-DIP

This principle has no meaning at all from the name. Simply put, it is to try to be interface-oriented programming.

The manifestation of the dependency inversion principle in the Java language is that the dependencies between modules occur through abstraction, and there is no direct dependency between implementation classes, and the dependencies are generated through interfaces or abstract classes .

  • Interfaces Sergregation Principle-ISP

The definition of the interface isolation principle is: the client should not rely on the interface it does not need; the dependence of one class on another should be established on the smallest interface . The interface is minimized, and the bloated interface can be divided into multiple interfaces according to the function.

The above design ideas can be composed of SOLID with the first letter of English. A program that meets these 5 principles is also known as meeting the SOLID criteria.

  • Law of Demeter-LOD

Dimit's principle is also called the principle of minimum knowledge, his definition: an object should maintain a minimum understanding of other objects .
Because the closer the relationship between the class and the class, the greater the degree of coupling, when one class changes, the greater the impact on another class, so this is also the general principle of software programming that we advocate: low coupling, high Cohesion .

Guess you like

Origin blog.csdn.net/why1092576787/article/details/114847782