The design pattern describes a general solution to a certain type of common problems in the software design process.
The object-oriented design pattern is part of the design pattern. It describes common organizational relationships between classes and communication objects in specific scenarios during the object-oriented design process.
The object-oriented design model is a "good object-oriented design" that can meet the needs of "responding to changes and improving reuse" design.
From a macro perspective, the object-oriented construction method can better adapt to software changes and minimize the impact of changes
At the micro level, the object-oriented model emphasizes the responsibilities of various classes.
Historical Works: <design patterns: Basis for reusable object-oriented software> GoF23 Design Patterns
Design principles:
1. Programming for interfaces, rather than for implementation
The customer program (the program that calls your program) does not need to know the specific type of the object in use, but only needs to know that the object has the interface that the customer Program expects.
2. The object combination is preferred, instead of class inheritance.
Class inheritance is usually "white box reuse", and the object combination is usually "black box reuse". Inheritance damages encapsulation to some extent, and the Child class parent class has a high Coupling Degree, inheritance Is usually used only when A Is a B, while object combination only requires the combined object to have A well-defined interface, and the coupling degree Is low.
3. encapsulation changes
Create the Division layer between objects using the sub-assembly (encapsulate the changed part in one place and encapsulate the part that does not need to be changed frequently in another place), so that the designer can modify the part on one side of the decomposition layer, without adverse effects on the other side, so as to achieve loose coupling between layers.
4. Use the refactoring Mode
The application of the design pattern should not be preemptible. From the very beginning, the use of the design pattern is the biggest misuse of the design pattern, and there is no one-step design pattern, the "refactoring to patterns" advocated by agile software development practices is currently recognized as the best way to use the design pattern.
Several more specific design principles
1. Single Responsibility Principle (SRP)
A class should have only one reason for its change.
2. Open and closed principle (OCP)
Class modules should be extensible, but cannot be modified (open to extensions and closed to changes)
3. Liskov replacement principle (LSP)
Subclass must be able to replace their base classes
4. Dependency inversion principle
High-level modules should not depend on low-level modules, both of which should depend on abstraction.
Abstraction should not depend on implementation details. Implementation Details should depend on abstraction.
5. Interface isolation principles
Customer programs should not be forced to rely on methods they do not need