A preliminary understanding of design patterns

1. What design pattern?

Design patterns are what software developers face during the software development processGeneral Questionsofsolution. These solutions are the result of trial and error by numerous software developers over a considerable period of time.

2. What is the role of design patterns?

Design patterns can help us enhance code reusability, scalability, maintainability, and flexibility. The ultimate purpose of our use of design patterns is to achieve the 高内聚sum of the code 低耦合.

3. What design patterns do you use in your projects?

https://blog.csdn.net/qq_31279347/article/details/82462336

Multi-user login (customer, store clerk, inventory manager, boss). Adopt strategy mode

Display product images to customers on the page. Image loading in singleton mode

Customers place an order and notify store staff and inventory managers. using the observer pattern

Store staff apply for purchase, increase inventory, if it is less than 500, the inventory manager will directly approve it; if it is more than 500, it will be directly approved by the boss. Adopt Chain of Responsibility Model

4. What are the four basic elements of a pattern?

1. Pattern name A mnemonic name that uses one or two words to describe the problem, solution, and effect of a pattern.
2. The problem describes the mode that should be used in an appropriate manner. It addresses the design problem and the context in which the problem exists, it may describe a specific design problem, or it may describe the class or object structure that leads to an inflexible design.
3. The solution describes the components of the design, their interrelationships and their respective responsibilities and collaboration methods.
4. Effects (consequences) Describe the effects of pattern application and the issues that should be weighed when using patterns.

5. Learn Design Patterns for Websites

https://refactoring.guru/design-patterns/catalog

6. Six basic principles of design patterns

  • Single Responsibility Principle
  • Liskov Substitution Principle
  • Dependency Inversion Principle
  • Interface Segregation Principle
  • Law of Demeter
  • open-closed principle

7. Design patterns are divided into three categories

There are 5 types of creational patterns: factory method pattern, abstract factory pattern, singleton pattern, builder pattern, prototype pattern.
There are 7 structural patterns in total: adapter pattern, decorator pattern, proxy pattern, appearance pattern, bridge pattern, composition pattern, and flyweight pattern.
There are 11 behavioral patterns: strategy pattern, template method pattern, observer pattern, iteration sub pattern, responsibility chain pattern, command pattern, memorandum pattern, state pattern, visitor pattern, mediator pattern, interpreter pattern.

8. Design pattern diagram

I also think it is quite complicated, so let's look at it like this for a while;
insert image description here

Guess you like

Origin blog.csdn.net/Yearingforthefuture/article/details/121665044