For the design of object-oriented software systems, improving system reusability while supporting maintainability is a crucial issue, how to Improve the maintainability and reusability of a software system at the same time is one of the core issues that need to be addressed in object-oriented design. In object-oriented design, the reuse of maintainability is based on the design principles. Each principle contains some object-oriented design ideas that can improve the design level of a software architecture from different perspectives.
Object-Oriented Design Principles were born to support maintainability reuse. These principles are embodied in many design patterns and are guiding principles summarized from many design schemes.. The object-oriented design principle is also one of the important indicators for us to evaluate the use effect of a design model. In the learning of the design model, we often see statements such as "XXX mode conforms to XXX principles" and "XXX mode violates XXX principles.
The seven most common object-oriented design principles are shown in the following table:
Table 1 seven common object-oriented design principles
Design Principle Name |
Definition |
Usage Frequency |
Single Responsibility Principle (Single responsibility principle, SRP) |
One class is only responsible for the corresponding responsibilities in one functional area |
★★★★☆ |
Principle of opening/closing (Open-closed principle, OCP) |
The software entity should be open to expansion and closed to Modification |
★★★★★ |
Rishi replacement principle (Liskov substitution principle, LSP) |
All objects that reference base class objects can transparently use their subclass objects. |
★★★★★ |
Dependency reversal Principle (Dependence inversion principle, DIP) |
Abstraction should not depend on details, and details should depend on abstraction |
★★★★★ |
Interface isolation principle (Interface segregation principle, ISP) |
Use multiple dedicated interfaces instead of a single total Interface |
★★☆☆☆ |
Merging Reuse Principle (Composite Reuse Principle, CRP) |
Try to use object combinations instead of inheritance for reuse purposes. |
★★★★☆ |
Dimit Law (Law of Demeter, D3S) |
A software entity should interact with other entities as little as possible |
★★★☆☆ |
[Author: Liu Wei http://blog.csdn.net/lovelion]