Design Patterns Study Notes (a) - six principles and three types
Others
2019-08-30 06:19:14
views: null
1.1 six principles (general principles - the principle of opening and closing: open for extension, closed for modification.)
- Single Responsibility Principle
- Do not type more than one cause of change, which means that each class should implement a single responsibility, otherwise it should split the class.
- Richter substitution principle (Liskov Substitution Principle)
- Supplement - "closed on" the principle of
- Inheritance is the cornerstone of reuse: where any base class can appear, sub-class will be able to appear.
- Dependency Inversion principle (Dependence Inversion Principle)
- Oriented programming interface, dependent on the abstract does not depend on the specific
- Interface Segregation Principle (Interface Segregation Principle)
- Each interface does not exist in subclasses, but not by the method to be implemented, if otherwise, it is necessary to split the interface
- Demeter (the least known principle) (Demeter Principle)
- A class of their dependent classes know, the better
- Another expression of the least known principle is: only direct communication with friends.
As long as there is coupling relationship called friendship between classes. Coupling into dependency, association, aggregation, and the like combinations.
We call appears as a member variable, method arguments, method return values directly in the class friends.
Local variables, temporary variables are not direct friends. We ask strangers class do not appear as a local variable in the class.
- Synthesis of multiplexing principles (Composite Reuse Principle)
- Try first synthetic polymeric info / instead of inheritance.
1.2 three types
- Creator mode (Creational Pattern)
- Examples of process for the abstract class, can be used to create software modules and objects in the object separation
- Structural model (Structural Pattern)
- Describes how to combine together to form a larger class of objects or structures;
- Class can be divided into structural model and object structures schema
- Behavioral patterns (Behavioral Pattern)
- Not only concerned about the structure of classes and objects, but also focus on the interaction between them, and the algorithm is a division of responsibilities between the different objects of abstraction
- Divided into two categories behavioral patterns and object behavioral patterns
- The "Synthesis of multiplexing principles", the system should try to use the relationship inheritance substituted
Origin www.cnblogs.com/kintanx/p/11432233.html