你怎么知道何时使用设计模式?

时间:2022-06-20 21:28:21

Anyone can read the GoF book to learn what design patterns are and how to use them, but what is the process for figuring out when a design pattern solves a problem? Does the knowledge of the pattern drive the design, or is there a way to figure out how a pattern can be used to change a design?

任何人都可以阅读GoF书籍以了解设计模式是什么以及如何使用它们,但是什么是确定设计模式何时解决问题的过程?模式的知识是否推动了设计,或者有没有办法弄清楚如何使用模式来改变设计?

In other words, are there patterns for Patterns?

换句话说,模式有模式吗?

14 个解决方案

#1


36  

Design patterns are supposed to provide a structure in which problems can be solved. When solving a real problem, you have to consider many tiny variations of a solution to that problem to see whether any fits a design pattern. In particular, you will probably need to generalise your problem, or its solution, in order to make a design pattern fit.

设计模式应该提供一个可以解决问题的结构。在解决实际问题时,您必须考虑该问题的解决方案的许多微小变化,以确定是否符合设计模式。特别是,您可能需要概括您的问题或其解决方案,以使设计模式适合。

The answer is, it's an art. Knowing the design patterns is certainly an important step. One way to get used to this sort of thing is to study applications of design patterns, not just the patterns. Seeing many different applications of one pattern can help you over time to get better at mapping a task onto a pattern.

答案是,这是一门艺术。了解设计模式无疑是重要的一步。习惯这种事情的一种方法是研究设计模式的应用,而不仅仅是模式。查看一种模式的许多不同应用程序可以帮助您随着时间的推移更好地将任务映射到模式上。

#2


38  

I would highly recommend reading Head First Design Patterns from O'Reilly. This explains how these patterns can be used in the real world.

我强烈推荐阅读O'Reilly的Head First Design Patterns。这解释了如何在现实世界中使用这些模式。

你怎么知道何时使用设计模式?

I'd also add that don't try design too much with patterns in mind. More, look for "code smells" which a pattern might help solve.

我还要补充一点,不要试图设计过多的图案。更多,寻找模式可能有助于解决的“代码味道”。

#3


11  

Turn the question over: the pattern mtch you should be making is "what pattern fits my problem". Consider a really simple pattern, finding an element in an array. in C, it's something like

把问题翻过来:你应该做的模式是“什么模式适合我的问题”。考虑一个非常简单的模式,在数组中查找元素。在C中,它就像是

TYPE_t ary[SIZE] = // ... gets initialized somehow
size_t ix ;        // Your index variable

for(ix=0; ix < SIZE; ix++){
    if (ary[ix] == item) {
       return ix ;
    }
}

You don't look at the code and think "where can I use that", you look at the problem and say "do I know how to find an element in an array?"

你不看代码并想“我在哪里可以使用它”,你看问题并说“我知道如何在数组中找到一个元素吗?”

With more extensive patterns is really works the same way. You need to have many many copies of a data structure that doesn't change often --- that makes you think "Flyweight." You want something that lives on both sides of a network boundary, you think Proxy.

更广泛的模式确实以同样的方式工作。您需要拥有许多不经常更改的数据结构副本 - 这会让您想到“Flyweight”。你想要一些生活在网络边界两侧的东西,你认为是代理。

When you study patterns, especially the GoF, ask yourself "what situations call for this pattern? Have I seen this pattern before? What could I have used this for in previous work? Where can I find an example of this in my own life?"

当你研究模式,特别是GoF时,问问自己“这种模式需要什么样的情况?我以前看过这种模式吗?在以前的工作中我可以用它做什么?我在哪里可以找到一个这样的例子? “

#4


11  

There's a core concept underlying patterns that most people don't grok. Don't think of them as data structures, or algorithms.

有一个核心概念是大多数人不会理解的模式。不要将它们视为数据结构或算法。

Instead, think of your code as people sending messages, like passing notes or sending letters, to each other. Each object is a 'person'.

相反,将您的代码视为发送消息的人,例如传递笔记​​或发送信件。每个对象都是“人”。

The way that you'd organize the 'people' and the patterns they use to send messages to each other are the patterns.

您组织“人员”的方式以及他们用来向对方发​​送消息的模式是模式。

#5


7  

Design Patterns? You're soaking in them!

设计模式?你在浸泡它们!

There's nothing special about design patterns, they are merely patterns of design. All development uses design patterns. There are a certain set of design patterns in object oriented programming which are considered generally desirable and have become the canonical Design Patterns. But there are also many undesirable or otherwise indifferent design patterns (such as design anti-patterns) as well as undiscovered and/or undocumented patterns.

设计模式没有什么特别之处,它们只是设计模式。所有开发都使用设计模式。在面向对象的编程中存在一组特定的设计模式,这些模式被认为是通常期望的并且已经成为规范的设计模式。但是也存在许多不期望的或其他无关紧要的设计模式(例如设计反模式)以及未发现和/或未记录的模式。

You can't avoid using patterns when programming. But you can become more aware of the patterns you are using and of when certain patterns are useful and when they are not. Studying the canonical Design Patterns from the GoF book will help, as will learning about code smells and refactoring. There's no one right answer for when a particular design or design pattern should be used, you need to build up experience in using and implementing them in order to know when and where to use which pattern.

编程时无法避免使用模式。但是你可以更加了解你正在使用的模式,以及某些模式何时有用以及何时模式不可用。从GoF书中学习规范设计模式将有助于学习代码气味和重构。对于何时应该使用特定的设计或设计模式,没有一个正确的答案,您需要积累使用和实现它们的经验,以便知道何时何地使用哪种模式。

#6


6  

Experience. Learn the patterns and real-world examples of their uses. Every time you have a design decision to make, think if a pattern you know would apply to it. Over time, you get better and you discover new ways to apply the patterns to a wider range of problems.

经验。了解其用途的模式和实际示例。每当您做出设计决策时,请考虑您知道的模式是否适用于它。随着时间的推移,您会变得更好,并且您会发现将模式应用于更广泛问题的新方法。

#7


4  

Another great book I found was:

我找到的另一本好书是:

Refactoring to Patterns

重构模式

By showing when, where and how you can alter existing code to patterns, it gave me a much better understanding of the concepts, and an ability to identify where they can be used.

通过显示何时,何地以及如何将现有代码更改为模式,它使我更好地理解了这些概念,并能够识别它们的使用位置。

#8


4  

Rian van der Merwe wrote an excellent article on this for Smashing Magazine in June 2012. Here are some salient bullet points.

Rian van der Merwe在2012年6月为Smashing Magazine撰写了一篇很好的文章。这里有一些重要的要点。

Design patterns are useful for two reasons:

设计模式有两个原因:

  1. Patterns save time because we don’t have to solve a problem that’s already been solved.
  2. 模式可以节省时间,因为我们不必解决已经解决的问题。

  3. Patterns make the Web easier to use because, as adoption increases among designers, users get used to how things work, which in turn reduces their cognitive load when encountering common design elements.
  4. 模式使Web更易于使用,因为随着设计人员的采用增加,用户会习惯于工作方式,这反过来会降低他们在遇到常见设计元素时的认知负担。

van der Merwe recommends that we consider breaking patterns when:

van der Merwe建议我们在以下情况下考虑打破模式:

  1. The new way empirically improves usability, or
  2. 新方法凭经验改善了可用性,或者

  3. The established way becomes outdated.
  4. 既定的方式已经过时了。

#9


3  

How did you learn when to use an if statement?

你是如何学习何时使用if语句的?

I liken it to that because its a larger construct that you need to know the ins and outs of before you can use it effectively. An if statement solves a class of problems needing branching. A bridge pattern solves a class of problems. I really don't view them any differently.

我把它比作它,因为它是一个更大的构造,你需要知道它的来龙去脉才能有效地使用它。 if语句解决了一类需要分支的问题。桥模式解决了一类问题。我真的不会以任何不同的方式看待它们。

#10


3  

If you know the patterns, then they become tools in your toolbox. When you look at a task, you select from your tools. At that point you should have a pretty good idea which tool is the best fit for a given problem. This is where formulas stop working and you actually do engineering work.

如果您了解模式,那么它们就会成为工具箱中的工具。查看任务时,可以从工具中进行选择。那时你应该非常清楚哪个工具最适合给定的问题。这是公式停止工作的地方,你实际上是在做工程工作。

#11


2  

I agree that just learning the patterns is not enough. The problem with most books is that they do not provide real-world examples. I've heard that Head First Design Patterns, as some suggested earlier, is a good one.

我同意仅仅学习模式是不够的。大多数书籍的问题在于它们不提供真实的例子。我听说Head First Design Patterns,正如之前的一些建议,是一个很好的。

Another thing is that most books are intentionally not language-specific, which may be both a good or a bad thing for you. However important is to understand a pattern in general, it is equally important to know how to implement it well. I've come across a book called C# 3.0 Design Patterns which devotes just about equal ink to both of these unseparable aspects.

另一件事是,大多数书籍都是故意不是针对特定语言的,这对你来说既可能是好事也可能是坏事。无论如何重要的是理解一般的模式,知道如何很好地实现它同样重要。我遇到过一本名为C#3.0设计模式的书,它将这些不可分割的两个方面都用于相同的墨水。

#12


2  

I had this same question when I first encountered design patterns. I appreciated the concepts, but didn't know when or how to apply them. My initial approach was to look for applicability during the design phase. Once you have a block diagram and semi-clear responsibilities for each block, its not too hard to take the responsibilities and cross reference them with a decent reference book. Several good ones have been mentioned here, but the GoF one should be on your list. The next step is to look for improvements in the design based on what you see in the patterns.

我第一次遇到设计模式时遇到了同样的问题。我很欣赏这些概念,但不知道何时或如何应用它们。我最初的方法是在设计阶段寻找适用性。一旦你有了每个区块的方框图和半清晰的责任,它就不太难以承担责任并用一本体面的参考书交叉引用它们。这里提到了几个好的,但GoF应该在你的名单上。下一步是根据您在模式中看到的内容寻找设计的改进。

#13


2  

The concept of a design pattern has been taken from structural engineering, as with many practices in software engineering. If you consider building a structure, there are decisions that need to be made on how to build that structure to achieve the goals set out. When making those decisions, you will have a set of requirements to work from. It may be something as simple as Bridge must be able to support X tons at one time, or have a particular tensile strength to allow enough movement in wind etc. An architect would use prior knowledge of other builds to make those design choices. He/She would be very unlikely to try to solve the problem from scratch.

设计模式的概念取自结构工程,与软件工程中的许多实践一样。如果您考虑构建结构,则需要就如何构建该结构以实现所设定的目标做出决策。在做出这些决定时,您将有一系列要求可供使用。它可能很简单,因为Bridge必须能够同时支撑X吨,或者具有特定的拉伸强度以允许在风等中有足够的移动。建筑师可以使用其他构建的先验知识来做出这些设计选择。他/她不太可能尝试从头开始解决问题。

Software Engineering and Design Patterns are exactly the same. They are simply common solutions to common problems. If you know the design patterns, then when you are working through a design, and particular part of a system requires something that fits a design pattern you have, then use it. Don't try to fit a system round a design pattern, fit design patterns in to your system (where they fit). Just try to think of them as a set of solutions to reduce the amount of design work you need to do, and be cautious of over-engineering your solutions to cram in as many design patterns as you can. This will just serve to make your solution unmaintainable and probably quite buggy.

软件工程和设计模式完全相同。它们只是常见问题的常见解决方案。如果您了解设计模式,那么当您处理设计时,系统的特定部分需要适合您的设计模式,然后使用它。不要试图使系统适合设计模式,使设计模式适合您的系统(适合它们的地方)。只是尝试将它们视为一组解决方案,以减少您需要做的设计工作量,并谨慎地过度设计您的解决方案,尽可能多地填充设计模式。这只会使您的解决方案无法维护,而且可能非常多。

#14


0  

A design pattern is a generic description on how to solve a common problem. There're 2 things we should pay attention to:

设计模式是关于如何解决常见问题的一般描述。我们应该注意两件事:

First, it is a Generic description; it's not the concrete solution, and it's not a complete recipe either, it's just a description on how the solution would look like in order to approach a common problem.

首先,它是一个通用的描述;它不是具体的解决方案,也不是一个完整的配方,它只是描述解决方案如何处理常见问题。

Second, the problem is question is a common problem:, that means this problem has been encountered many times before, and over time people developed a description for how an ideal solution can be applied to this commonly repeated problem.

其次,问题是问题是一个常见的问题:这意味着此问题之前已经遇到过很多次,并且随着时间的推移,人们开始描述如何将理想的解决方案应用于这个通常重复的问题。

So, if you're encountering a new problem that's not common, try not to use design patterns to solve it, or at least don't make design patterns your tool to just solve any kind of problem you face.

因此,如果您遇到一个不常见的新问题,请尽量不使用设计模式来解决它,或者至少不要将设计模式作为解决您遇到的任何问题的工具。

#1


36  

Design patterns are supposed to provide a structure in which problems can be solved. When solving a real problem, you have to consider many tiny variations of a solution to that problem to see whether any fits a design pattern. In particular, you will probably need to generalise your problem, or its solution, in order to make a design pattern fit.

设计模式应该提供一个可以解决问题的结构。在解决实际问题时,您必须考虑该问题的解决方案的许多微小变化,以确定是否符合设计模式。特别是,您可能需要概括您的问题或其解决方案,以使设计模式适合。

The answer is, it's an art. Knowing the design patterns is certainly an important step. One way to get used to this sort of thing is to study applications of design patterns, not just the patterns. Seeing many different applications of one pattern can help you over time to get better at mapping a task onto a pattern.

答案是,这是一门艺术。了解设计模式无疑是重要的一步。习惯这种事情的一种方法是研究设计模式的应用,而不仅仅是模式。查看一种模式的许多不同应用程序可以帮助您随着时间的推移更好地将任务映射到模式上。

#2


38  

I would highly recommend reading Head First Design Patterns from O'Reilly. This explains how these patterns can be used in the real world.

我强烈推荐阅读O'Reilly的Head First Design Patterns。这解释了如何在现实世界中使用这些模式。

你怎么知道何时使用设计模式?

I'd also add that don't try design too much with patterns in mind. More, look for "code smells" which a pattern might help solve.

我还要补充一点,不要试图设计过多的图案。更多,寻找模式可能有助于解决的“代码味道”。

#3


11  

Turn the question over: the pattern mtch you should be making is "what pattern fits my problem". Consider a really simple pattern, finding an element in an array. in C, it's something like

把问题翻过来:你应该做的模式是“什么模式适合我的问题”。考虑一个非常简单的模式,在数组中查找元素。在C中,它就像是

TYPE_t ary[SIZE] = // ... gets initialized somehow
size_t ix ;        // Your index variable

for(ix=0; ix < SIZE; ix++){
    if (ary[ix] == item) {
       return ix ;
    }
}

You don't look at the code and think "where can I use that", you look at the problem and say "do I know how to find an element in an array?"

你不看代码并想“我在哪里可以使用它”,你看问题并说“我知道如何在数组中找到一个元素吗?”

With more extensive patterns is really works the same way. You need to have many many copies of a data structure that doesn't change often --- that makes you think "Flyweight." You want something that lives on both sides of a network boundary, you think Proxy.

更广泛的模式确实以同样的方式工作。您需要拥有许多不经常更改的数据结构副本 - 这会让您想到“Flyweight”。你想要一些生活在网络边界两侧的东西,你认为是代理。

When you study patterns, especially the GoF, ask yourself "what situations call for this pattern? Have I seen this pattern before? What could I have used this for in previous work? Where can I find an example of this in my own life?"

当你研究模式,特别是GoF时,问问自己“这种模式需要什么样的情况?我以前看过这种模式吗?在以前的工作中我可以用它做什么?我在哪里可以找到一个这样的例子? “

#4


11  

There's a core concept underlying patterns that most people don't grok. Don't think of them as data structures, or algorithms.

有一个核心概念是大多数人不会理解的模式。不要将它们视为数据结构或算法。

Instead, think of your code as people sending messages, like passing notes or sending letters, to each other. Each object is a 'person'.

相反,将您的代码视为发送消息的人,例如传递笔记​​或发送信件。每个对象都是“人”。

The way that you'd organize the 'people' and the patterns they use to send messages to each other are the patterns.

您组织“人员”的方式以及他们用来向对方发​​送消息的模式是模式。

#5


7  

Design Patterns? You're soaking in them!

设计模式?你在浸泡它们!

There's nothing special about design patterns, they are merely patterns of design. All development uses design patterns. There are a certain set of design patterns in object oriented programming which are considered generally desirable and have become the canonical Design Patterns. But there are also many undesirable or otherwise indifferent design patterns (such as design anti-patterns) as well as undiscovered and/or undocumented patterns.

设计模式没有什么特别之处,它们只是设计模式。所有开发都使用设计模式。在面向对象的编程中存在一组特定的设计模式,这些模式被认为是通常期望的并且已经成为规范的设计模式。但是也存在许多不期望的或其他无关紧要的设计模式(例如设计反模式)以及未发现和/或未记录的模式。

You can't avoid using patterns when programming. But you can become more aware of the patterns you are using and of when certain patterns are useful and when they are not. Studying the canonical Design Patterns from the GoF book will help, as will learning about code smells and refactoring. There's no one right answer for when a particular design or design pattern should be used, you need to build up experience in using and implementing them in order to know when and where to use which pattern.

编程时无法避免使用模式。但是你可以更加了解你正在使用的模式,以及某些模式何时有用以及何时模式不可用。从GoF书中学习规范设计模式将有助于学习代码气味和重构。对于何时应该使用特定的设计或设计模式,没有一个正确的答案,您需要积累使用和实现它们的经验,以便知道何时何地使用哪种模式。

#6


6  

Experience. Learn the patterns and real-world examples of their uses. Every time you have a design decision to make, think if a pattern you know would apply to it. Over time, you get better and you discover new ways to apply the patterns to a wider range of problems.

经验。了解其用途的模式和实际示例。每当您做出设计决策时,请考虑您知道的模式是否适用于它。随着时间的推移,您会变得更好,并且您会发现将模式应用于更广泛问题的新方法。

#7


4  

Another great book I found was:

我找到的另一本好书是:

Refactoring to Patterns

重构模式

By showing when, where and how you can alter existing code to patterns, it gave me a much better understanding of the concepts, and an ability to identify where they can be used.

通过显示何时,何地以及如何将现有代码更改为模式,它使我更好地理解了这些概念,并能够识别它们的使用位置。

#8


4  

Rian van der Merwe wrote an excellent article on this for Smashing Magazine in June 2012. Here are some salient bullet points.

Rian van der Merwe在2012年6月为Smashing Magazine撰写了一篇很好的文章。这里有一些重要的要点。

Design patterns are useful for two reasons:

设计模式有两个原因:

  1. Patterns save time because we don’t have to solve a problem that’s already been solved.
  2. 模式可以节省时间,因为我们不必解决已经解决的问题。

  3. Patterns make the Web easier to use because, as adoption increases among designers, users get used to how things work, which in turn reduces their cognitive load when encountering common design elements.
  4. 模式使Web更易于使用,因为随着设计人员的采用增加,用户会习惯于工作方式,这反过来会降低他们在遇到常见设计元素时的认知负担。

van der Merwe recommends that we consider breaking patterns when:

van der Merwe建议我们在以下情况下考虑打破模式:

  1. The new way empirically improves usability, or
  2. 新方法凭经验改善了可用性,或者

  3. The established way becomes outdated.
  4. 既定的方式已经过时了。

#9


3  

How did you learn when to use an if statement?

你是如何学习何时使用if语句的?

I liken it to that because its a larger construct that you need to know the ins and outs of before you can use it effectively. An if statement solves a class of problems needing branching. A bridge pattern solves a class of problems. I really don't view them any differently.

我把它比作它,因为它是一个更大的构造,你需要知道它的来龙去脉才能有效地使用它。 if语句解决了一类需要分支的问题。桥模式解决了一类问题。我真的不会以任何不同的方式看待它们。

#10


3  

If you know the patterns, then they become tools in your toolbox. When you look at a task, you select from your tools. At that point you should have a pretty good idea which tool is the best fit for a given problem. This is where formulas stop working and you actually do engineering work.

如果您了解模式,那么它们就会成为工具箱中的工具。查看任务时,可以从工具中进行选择。那时你应该非常清楚哪个工具最适合给定的问题。这是公式停止工作的地方,你实际上是在做工程工作。

#11


2  

I agree that just learning the patterns is not enough. The problem with most books is that they do not provide real-world examples. I've heard that Head First Design Patterns, as some suggested earlier, is a good one.

我同意仅仅学习模式是不够的。大多数书籍的问题在于它们不提供真实的例子。我听说Head First Design Patterns,正如之前的一些建议,是一个很好的。

Another thing is that most books are intentionally not language-specific, which may be both a good or a bad thing for you. However important is to understand a pattern in general, it is equally important to know how to implement it well. I've come across a book called C# 3.0 Design Patterns which devotes just about equal ink to both of these unseparable aspects.

另一件事是,大多数书籍都是故意不是针对特定语言的,这对你来说既可能是好事也可能是坏事。无论如何重要的是理解一般的模式,知道如何很好地实现它同样重要。我遇到过一本名为C#3.0设计模式的书,它将这些不可分割的两个方面都用于相同的墨水。

#12


2  

I had this same question when I first encountered design patterns. I appreciated the concepts, but didn't know when or how to apply them. My initial approach was to look for applicability during the design phase. Once you have a block diagram and semi-clear responsibilities for each block, its not too hard to take the responsibilities and cross reference them with a decent reference book. Several good ones have been mentioned here, but the GoF one should be on your list. The next step is to look for improvements in the design based on what you see in the patterns.

我第一次遇到设计模式时遇到了同样的问题。我很欣赏这些概念,但不知道何时或如何应用它们。我最初的方法是在设计阶段寻找适用性。一旦你有了每个区块的方框图和半清晰的责任,它就不太难以承担责任并用一本体面的参考书交叉引用它们。这里提到了几个好的,但GoF应该在你的名单上。下一步是根据您在模式中看到的内容寻找设计的改进。

#13


2  

The concept of a design pattern has been taken from structural engineering, as with many practices in software engineering. If you consider building a structure, there are decisions that need to be made on how to build that structure to achieve the goals set out. When making those decisions, you will have a set of requirements to work from. It may be something as simple as Bridge must be able to support X tons at one time, or have a particular tensile strength to allow enough movement in wind etc. An architect would use prior knowledge of other builds to make those design choices. He/She would be very unlikely to try to solve the problem from scratch.

设计模式的概念取自结构工程,与软件工程中的许多实践一样。如果您考虑构建结构,则需要就如何构建该结构以实现所设定的目标做出决策。在做出这些决定时,您将有一系列要求可供使用。它可能很简单,因为Bridge必须能够同时支撑X吨,或者具有特定的拉伸强度以允许在风等中有足够的移动。建筑师可以使用其他构建的先验知识来做出这些设计选择。他/她不太可能尝试从头开始解决问题。

Software Engineering and Design Patterns are exactly the same. They are simply common solutions to common problems. If you know the design patterns, then when you are working through a design, and particular part of a system requires something that fits a design pattern you have, then use it. Don't try to fit a system round a design pattern, fit design patterns in to your system (where they fit). Just try to think of them as a set of solutions to reduce the amount of design work you need to do, and be cautious of over-engineering your solutions to cram in as many design patterns as you can. This will just serve to make your solution unmaintainable and probably quite buggy.

软件工程和设计模式完全相同。它们只是常见问题的常见解决方案。如果您了解设计模式,那么当您处理设计时,系统的特定部分需要适合您的设计模式,然后使用它。不要试图使系统适合设计模式,使设计模式适合您的系统(适合它们的地方)。只是尝试将它们视为一组解决方案,以减少您需要做的设计工作量,并谨慎地过度设计您的解决方案,尽可能多地填充设计模式。这只会使您的解决方案无法维护,而且可能非常多。

#14


0  

A design pattern is a generic description on how to solve a common problem. There're 2 things we should pay attention to:

设计模式是关于如何解决常见问题的一般描述。我们应该注意两件事:

First, it is a Generic description; it's not the concrete solution, and it's not a complete recipe either, it's just a description on how the solution would look like in order to approach a common problem.

首先,它是一个通用的描述;它不是具体的解决方案,也不是一个完整的配方,它只是描述解决方案如何处理常见问题。

Second, the problem is question is a common problem:, that means this problem has been encountered many times before, and over time people developed a description for how an ideal solution can be applied to this commonly repeated problem.

其次,问题是问题是一个常见的问题:这意味着此问题之前已经遇到过很多次,并且随着时间的推移,人们开始描述如何将理想的解决方案应用于这个通常重复的问题。

So, if you're encountering a new problem that's not common, try not to use design patterns to solve it, or at least don't make design patterns your tool to just solve any kind of problem you face.

因此,如果您遇到一个不常见的新问题,请尽量不使用设计模式来解决它,或者至少不要将设计模式作为解决您遇到的任何问题的工具。