設計模式之How to Select a Design Pattern 如何選擇設計模式


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的列出了設計模式在設計是獨立的變化,從而讓你在沒有重新設計他們之前進行改變。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章