Home  >  Article  >  How to choose a design pattern?

How to choose a design pattern?

Guanhui
GuanhuiOriginal
2020-06-28 16:02:342712browse

Methods for selecting design patterns: 1. Consider how design patterns solve design problems; 2. Browse the intent part of the pattern; 3. Research how patterns relate to each other; 4. Research patterns with similar purposes; 5. Examine the reasons for redesign; 6. Consider what is variable in the design.

How to choose a design pattern?

There are more than 20 design patterns for you to choose from in GOF design patterns. It may be difficult to find a pattern that targets a specific design problem, especially It's when you're faced with a new set of patterns that you're not very familiar with yet. Here are a few different ways to help you discover design patterns that fit the problem at hand:

  • Consider how design patterns solve design problems. Section 1.6 discusses how design patterns help you find the right objects, determine the granularity of objects, specify object interfaces, and several other ways design patterns solve design problems. Referring to these discussions will help you find the right model.

  • The intent part of the browse mode. Section 1.4 lists the intent sections of all schemas in the directory. Read through the intent of each pattern and identify the pattern or patterns that are relevant to your problem. You can use the classification methods shown in Table 1-1 to narrow the scope of your search.

  • Study how patterns relate to each other. Figure 1-1 graphically shows the relationship between design patterns. Studying these relationships can guide you to the appropriate pattern or group of patterns.

  • Study patterns with similar purposes. There are three chapters in the pattern classification description part, one chapter introduces creational patterns, one chapter introduces structural patterns, and one chapter introduces behavioral patterns. Each chapter begins with an introductory evaluation of the pattern and ends with a subsection of comparison and contrast. These subsections give you insight into the commonalities and differences between patterns that serve similar purposes.

  • Check out the reasons for the redesign. Take a look at the various causes of redesign discussed starting with the section "Design should support change" and see if your problem is related to them, and then identify patterns that can help you avoid these causes of redesign. .

  • Consider what is variable in your design. This approach is the opposite of focusing on what caused the redesign. It's not about thinking about what will force your design to change, but about what changes you want without necessitating a redesign. The main one is the concept of encapsulating changes, which is a theme of many design patterns. Table 1-2 lists the aspects of design patterns that allow you to change them independently without incurring a redesign.

How to choose a design pattern?

Recommended tutorial: "PHP"

The above is the detailed content of How to choose a design pattern?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn