The Strategy design pattern takes a little more work to implement than the Template Method pattern, but it is more flexible.
策略设计模式比模板方法模式花费了更多的工作去实现,但是它也更灵活。
Always make the abstract parent class implement an interface. The Template Method design pattern is especially valuable in framework design (discussed towards the end of this chapter).
总是使抽象父类实现一个接口。模板方法设计模式在框架设计中特别有价值(在这章的结尾讨论了)。
An alternative to the Template Method is the Strategy design pattern, which factors the variant behavior into an interface.
模板方法模式的另一个选择是策略模式,它抽取了多变的行为到一个接口中。
应用推荐