《设计模式解析》 第19章 Observer 模式 复习题

来源:互联网 发布:php获取js变量 编辑:程序博客网 时间:2024/05/17 23:16

Review Questions

Observation

1:

The Template Method pattern makes the method call in a special way. What is that?

将方法的调用延迟到派生类中。

Interpretation

1:

According to the Gang of Four, the intent of the Template Method pattern is to "define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Redefine the steps in an algorithm without changing the algorithm's structure." What does this mean?

定义各个方法以及方法调用的顺序,而对于某些方法的实现,则让派生类去实现。这样,派生类可以根据自己的需要对这些方法进行定义,而不会影响到父类。

2:

The Gang of Four calls this a "Template Method." Why do they do this?

他定义了一个方法实现的模板,将各个方法的调用顺序都给出了,我们需要做的仅是根据自己的需要在派生类中实现这些方法的具体细节。

3:

What is the difference between the Strategy pattern (Chapter 9) and the Template Method pattern?

模板方法是改变算法的一部分。

策略模式是使用委托改变整个算法。

原创粉丝点击