Introduction to design principles of facial image objects and Object Design Principles
I. Object-oriented Design Principles
- Single Responsibility Principle (SRP)
- Open/closed principle (OCP)
- LSP)
- Dependency inversion principle (DIP)
- Interface isolation principle (LSP)
- Dumit principles (LOP)
- Principle of combination/aggregation reuse (CARP)
II,
Single Responsibility Principle (SRP)
- Definition: each class in the system should have a responsibility
- Advantages: High Cohesion and low coupling
- High cohesion refers to a class or function module that consists of highly correlated code. classes or modules are difficult to split and are only responsible for one task.
- Coupling refers to the mutual relationship between classes or modules. The higher the coupling degree, the closer the connection is, and the worse the independence is. the more difficult it is to split, the lower the coupling degree, the loose the relationship, the better the independence, and the higher the possibility of reuse.
Development based on a single responsibility can reduce the size of a single class, reduce coupling, and improve the reusability of classes.
Iii. Open and Close principle (OCP)
- Open to extension and disable Modification
Advantages:
- Adaptability and flexibility
- Stability and continuity
- Reusability and maintainability
Iv. Lean replacement principle (LSP)
- Definition: it can be replaced by its subclass where any parent class appears without affecting the function. It is an extension of the open and closed principles.
- The Rys replacement principle expresses that objects in an inheritance system should share common external characteristics.
- The Rys replacement principle advocates that we use "abstraction" and "polymorphism" to change the static structure in the design to a dynamic structure.
- Object polymorphism is actually an example of the best Lee's replacement principle.
V. Dependency inversion principle (DIP) (control inversion)
- Definition: the high-level module should not depend on the underlying module, both of which should depend on abstraction;Abstraction should notDependencyDetails; details should depend on abstraction.
- Interfaces are responsible for the declaration of public methods. abstract classes are responsible for the implementation of public methods. Similar to the open and closed principles, they are not used to modify the original program when the program adds new functions.
- Interface-Oriented Programming
- Benefits: Improves program stability, maintainability, and scalability.
Vi. Interface isolation principle (LSP)
Definition: it is better to use multiple special interfaces than to use a single total interface.
Advantage: Do not force unnecessary implementation of new functions
VII. dimit principle (LOP) (minimum knowledge principle)
Definition: an object should have as little understanding as possible about other objects and be understood as much as possible by fewer objects.
When a class needs to call a method of another class, it is implemented through the intermediary class.
Minimize access levels
Advantage: reduced Coupling
Disadvantages: over-use, reduced communication efficiency, and a large number of intermediary classes
Cannot be used excessively
8. Principle of combination/aggregation reuse (CARP)
Definition: The combination is preferred, and the system is more flexible. The inheritance is considered to achieve reuse.
Advantages:
- Combination reuse requires less Dependencies
- Combination reuse can be performed dynamically during running time, and new objects can dynamically reference objects of the same type as component objects.
Disadvantage: there will be a lot of objects to be managed in a system built by combined use.