Labels: C ++ solid principle object-oriented design ideas
The solid principle of Object-Oriented Design
SRP the single responsibility principle single Responsibility Principle
OCP the open closed principle Principle
LSP the liskov substitution principle's replacement principle
Dip the Dependency inversion principle
ISP the interface segregation principle interface separation principle
Single responsibility principle:
There is only one reason for modifying a class. In other words, let a class only take one type of responsibility. When this class needs to take responsibility for other types of responsibilities, it needs to be broken down.
Principle of opening and closing:
The software entity should be extensible and unchangeable. That is to say, it is open to extensions and closed to modifications. This principle is the most abstract and hard to understand among many object-oriented programming principles.
Lee's replacement principle:
When a subclass instance should be able to replace any of its superclasses, There Is A is-a relationship between them.
Dependency inversion principle:
1. High-level modules should not depend on low-level modules. Both of them should depend on abstraction.
2. abstraction should not depend on details, but on abstraction.
Interface separation principle:
Users cannot be forced to rely on interfaces they do not use. In other words, it is better to use multiple dedicated interfaces than to use a single total interface.
The main progress of object-oriented development is to encapsulate and hide data. Looking at objects from the outside is like a "black box". data and methods are hidden and invisible. When using an object, you do not need to know the specific implementation details of the object. You only need to access the object based on the external interface provided by the object.
Encapsulation: Put the data of an object together with the operations related to the data. Each object is independent of each other and does not interfere with each other. Only a small number of interfaces are left for external contact.
Encapsulation should have the following characteristics:
With a clear boundary, Private Members are encapsulated inside, and external access is not allowed to provide necessary interfaces.
The data and methods inside the object are protected by the Encapsulation Shell. Other objects cannot be used directly.
The solid principle of Object-Oriented Design