Design Principles

This article mainly organizes some design principles of object-oriented design.

Good software needs to achieve the following points:
    maintainable, reusable, extensible, and flexible. The advantages of high cohesion and low coupling

object-oriented:
   reduce the coupling degree of the program through encapsulation, inheritance, and polymorphism.
   Using design patterns can make the program more flexible, easy to modify, and easy to reuse

 

Single Responsibility Principle

   Single Responsibility Principle (SRP), for a class, there should be only one reason for it to change.

 

Open-Closed Principle The
   Open-Closed Principle states that software entities (classes, modules, functions, etc.) should be extensible, but not modifiable

 

Dependency Inversion Principle

   A. High-level modules should not depend on low-level modules, both should depend on abstractions

   B. Abstraction should not depend on details, details should depend on abstraction

 

Liskov Substitution Principle

  According to the Liskov Substitution Principle (LSP), subtypes must be able to replace their supertypes.

 

Law of Demeter

   A software entity should interact with other entities as little as possible.

   If the two objects do not have to communicate directly with each other, then the two objects should not have any direct interaction. If one of the objects needs to call a method of the other object, the call can be forwarded through a third party

   Also known as the principle of least knowledge. The Law of Demeter can reduce the coupling degree of the system and keep loose coupling between classes. 

   

Interface Segregation Principle (ISP) 

  Dependencies of one class on another should be built on the smallest interface. 

 

Synthesis/Aggregation Multiplexing Principle

 The principle of composite reuse is to use some existing objects in a new object to make it a part of the new object, and the new object achieves the purpose of reusing the existing functions through the delegation of these objects. His design principle is: try to use composition/aggregation, try not to use inheritance.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326330524&siteId=291194637