《设计模式解析》 第13章 用模式解决CADCAM问题 复习题
Review Questions
Observations
What are the three steps of software design with patterns that the authors use? 1、找出模式 2、分析和应用模式:按北京的创造顺序将模式排序、选择模式并扩展设计、找到其他模式、重复 3、添加细节 | |
Define context. 一些 事物存在或发生所处的相互有关的情况——一种环境、一种场景。 | |
Define seniormost pattern. 最高模式为其他模式提供背景,约束其他的模式。 | |
When comparing two patterns, what are the two rules for discerning which pattern might be "seniormost"? 1、一个模式定义了另一个模式的行为? 2、有没有两个模式相互影响? | |
Define generic structure of a pattern. When is it used? Adapter:将一个接口转换为客户希望的另一个接口。使得原本由于接口不兼容而不能一起工作的类能够一起工作。(图略) 当我们需要将自己的设计转化为模式的标准形式时,使用它。 |
Interpretations
Can a problem always be defined in terms of patterns? If not, what else is needed? 不能。需要有问题所考虑的关键部分,问题实体间的相互关系。 | |
In the CAD/CAM problem, the Abstract Factory was rejected as the "seniormost" pattern. What were the reasons for this? 规则:先考虑系统中需要什么,然后再去关注如何创建他们。 因此,关于创建的模式往往放在后面考虑,因而不会成为背景模式。 | |
In the CAD/CAM problem, what were the reasons for labeling Bridge as senior to Adapter? 1、Adapter用于解决不同版本的接口一致性问题。提供的接口是由桥模式中的实现部分去调用。因此,桥模式使用了适配器模式,故桥在适配器之前。 |
Opinions and Applications
After all the patterns have been applied, there are still likely to be more details. Alexander's general rules (design by starting with the context) still apply. Does this ever stop? Is there ever a time when you should go ahead and dive into the details? Isn't that what "rapid prototyping" suggests? How can you avoid this temptation that all programmers have? Should you? | |
Compare the first solution to the CAD/CAM problem (Figure 13-12) with the new version (Figure 13-11). What do you like better about the new design? 必然是新版本的解决方案。他使得整个项目更灵活,有更强的复用性。去除了许多不必要的冗余。并且Feature和ImpFeature各司其职,让内聚性更高。V1System无需直接访问多个Feature,只需使用抽象的Feature,使得耦合性更低。 |