23 six principles of design patterns

Factory Method pattern

Abstract factory pattern

Prototype mode

Builder mode

Singleton

Structural pattern:

Decorative pattern

Proxy mode

Adapter mode

Flyweight

Facade pattern

Combined mode

Bridge Mode

Behavioral patterns:

Strategy Mode

Template Method Pattern

Observer Pattern

State mode

Memento Pattern

Iterator pattern

Command Mode

Duty chain.

Intermediary model

Interpreter pattern

Visitor Pattern

Six principles:

1. Single Responsibility Principle: To compare the official statement of the book is "On a category, should be only one of the causes of his change.". In fact, bluntly put, it is a class of functions as simple as possible, to avoid a class method functions in the package too much, too big to avoid it in the design category.

2, opening and closing principles: open for extension, but closed for modification. That is to say, when the requirements change, try not to change the existing code, but to add new code.

3, Richter substitution principle: In the program, a subclass can replace the parent and will not affect the operating results of the program. A typical example of this is the ostrich is a bird do? In biology, the ostrich is a bird, but in the object-oriented world, the ostrich is not a bird. Because if the bird as a class, then there must be a method birds fly, and the ostrich can not fly, so the ostrich can not inherit the birds.

4, Dependency Inversion Principle: abstract does not depend on the details, details depend on the abstract. In fact, this is the time to let us in program development, interface programming, rather than face to achieve.

5, synthetic polymeric multiplexing principle: To understand this principle is important to understand the concepts and polymeric synthesis. For chestnuts, geese and wings of the life cycle is the same, and therefore belong to the wings of geese and synthetic relationships. And geese and geese is an aggregation relationship. When we can use synthetic or polymeric, try not to use inheritance, and this actually reduces the coupling between classes, to avoid a multi-layer class because succession is very large.

6, Demeter (the least known principle): If two classes do not have to communicate directly with each other, then the two classes should not directly play a role. This requires us in the design category, to minimize access to members of the class. Its fundamental idea is actually a loosely coupled

Guess you like

Origin www.cnblogs.com/qiao298/p/11358325.html