introduce
Design patterns represent best practices and are usually adopted by experienced object-oriented software developers. .
in principle
Program the interface rather than the implementation;
prefer object composition over inheritance;
Types of
Creation
Instead of using the new keyword to directly instantiate the object, the creation logic is hidden while creating the object. Including: factory pattern, abstract factory pattern, singleton pattern, builder pattern and prototype pattern.
structural
These design patterns focus on the composition of classes and objects, and the concept of inheritance is used to compose interfaces and define the way in which composed objects obtain new functionality. Including: adapter mode, bridge mode, filter mode, composition mode, decorator mode, appearance mode, flyweight mode and proxy mode.
behavioral
These design patterns specifically focus on communication between objects. Including: chain of responsibility pattern, command pattern, interpreter pattern, iterator pattern, mediator pattern, memorandum pattern, observer pattern, state pattern, empty object pattern, strategy pattern, last shift pattern and visitor pattern.
in principle
open-closed principle
Open for extension, closed for modification.
Richter Exchange Principle
Wherever a base class can appear, a subclass must appear. When the derived class can replace the base class, and the function of the software unit is not affected, the base class can be reused, and the derived class can also add new behaviors based on the base class.
Dependency Inversion Principle
Program against interfaces and rely on abstractions rather than concreteness.
Interface Segregation Principle
Using multiple isolated interfaces is better than using a single interface, reducing the coupling between classes.
Law of Demeter (Least Knowing Principle)
An entity should interact with other entities as little as possible, so that the functional modules of the system are independent.
Synthetic reuse principle
Try to use composition/aggregation instead of inheritance.