您的位置:首页 > 其它

设计模式之How to Select a Design Pattern 如何选择设计模式

2013-11-27 20:16 501 查看
With more than 20 design patterns in thecatalog to choose from, it might be hard to find the one that addresses a particulardesign problem, especially if the

catalog is new and unfamiliar to you. Here are several different approaches to finding the design pattern that's right for your problem:

在目录中会有超过20中设计模式去选择,可能很难发现特别的问题,尤其是如果这个目录是新的或者你对它不熟悉。这里有几个不同方法去选择正确的设计模式来解决你的问题

1. Consider how design patterns solvedesign problems. Section 1.6 discusses how design patterns help you findappropriate objects, determine object

granularity, specify object interfaces, andseveral other ways in which design patterns solve design problems.Referring to these discussions can

help guide your search for the rightpattern.

考虑设计模式如何解决设计问题。章节1.6讨论了设计模式如何帮助你找到恰当的对象,决定对象的粒度,特别的对象接口,和设计模式解决问题的其他几个方法。这些可以帮助和指导你找到正确的设计模式。

2. Scan Intent sections. Section 1.4 (page18) lists the Intent sections from all the patterns in the catalog. Readthrough each pattern's intent to find

one or more that sound relevant to your problem. You can use the classification scheme presented in Table 1.1 (page 21) to narrow your search.

扫描的意图部分。在章节1.4(18页)有一个来自于目录中的所有模式的意图清单。 通过读这个清单来找到一个或者多个和你的问题相关的模式。你可以使用表1.1中的分类方案来缩小你搜索的范围。

3. Study how patterns interrelate. Figure1.1 (page 23) shows relationships between design patterns graphically.Studying these relationships can help direct you to the right pattern or group
of patterns.

研究设计模式之间的相互影响。图1.1(23页)展示了设计模式之间的关系。研究他们的关系可以帮助你找到一个正确的或者一组正确的设计模式。

4. Study patterns of like purpose. Thecatalog (page 93) has three chapters, one for creational patterns, another forstructural patterns, and a third

for behavioral patterns. Each chapterstarts off with introductory comments on the patterns and concludes with asection that compares and contrasts

them. These sections give you insight into the similarities and differences between patterns of like purpose.

研究设计模式的目的。目录(93页)有三章,一章是创建设计模式,另一章是设计模式的结构,最后一章是设计模式的行为。每章开始普遍是对设计模式的介绍,通过比较和参照得出结论。这部分会让你了解设计模式目的的相似点和不同点

5. Examine a cause of redesign. Look at the causes of redesign starting on page 37 to see if your problem involves one or more of them. Then look at the patterns that help you avoid the causes
of redesign.

仔细检查重新设计的原因。如果涉及到了一个或多个关于它们的问题,你可以在37页查看重新设计的原因。

6. Consider what should be variable in your design. This approach is the opposite of focusing on the causes of redesign. Instead of considering what might force a change to a design, consider
what you want to be able to change without redesign. The focus here is on encapsulating the concept that varies,

a theme of many design patterns. Table 1.2 lists the design aspect(s) that design patterns let you vary independently,thereby letting you change them

without redesign.

在设计中思考那些应该是一个变量。,设计这些方法和重新设计正好是相反的。不是考虑强迫设计做出改变,而是在没有进行重新设计之前考虑那些是你有能力去改变的。在这里关注的是在封装时变化的概念,这是很多设计模式的主题。表1.2的列出了设计模式在设计是独立的变化,从而让你在没有重新设计他们之前进行改变。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息