23 design patterns, commonly used design patterns, how many are used

23 design patterns, commonly used design patterns, how many are used

Overview

When designing the system architecture, we have to use its principles and principles to constantly seek technical balance points, and we have achieved sufficient flexibility in the architecture. The design pattern and design principle are the reusability, scalability and safety of the program design in the project.

Scenes

When we refactor a system, if the previous code is very bad, it will be difficult to understand, not easy to expand, and not easy to refactor. For example, a lot of if and else are used in the project; or some methods are very long and used There are a lot of new keywords. At this time, I have to think of using design patterns for transformation. An interface integrates the functions of several modules. At this time, design principles must be used to transform.

Design patterns and principles

The 23 design patterns are divided into three major
structural types: agency model, decoration model, adapter model, bridge model, combination model, flyweight model, appearance model and 7
behavior types: strategy model, intermediary model, observer model, chain of responsibility Mode, iteration mode, command mode, memo mode, state mode, template mode, visitor mode, interpreter mode 11
types of creation: singleton mode, abstract factory mode, prototype mode, builder mode, factory method mode 5
designs Principles: Single responsibility principle, opening and closing principle, Richter substitution principle, interface isolation principle, dependency inversion principle, combination principle, composite service principle

to sum up

Do not use design patterns for the sake of design patterns in the project. Consider the project development cycle and project scenarios, such as order modules. Because there are many states, you will think of state patterns and payment modules. There are multiple payment methods and different payments. The payment strategy is different, and you will definitely think of the strategy mode. Some classes in the project are heavy objects, and repeated creation will consume performance. At this time, you have to think of the singleton mode; when designing the interface, the order client interface can only define the order interface. Don't bring in other modules too, violating the principle of interface isolation. In short, when designing, we must seek various design balance points and design rationally.

Guess you like

Origin blog.51cto.com/xxdeelon/2536179