design pattern notes [5] - template method

755阅读 0评论2012-12-23 hanhuili
分类:C/C++

Template method lets abstract base class (this is the class to implement the algorithm) to implement invariant algorithm. The subclasses can redefine the algorithm when necessary. By this mechanism, we can reuse the code.
Normally, factory method is used by template to get instance of concrete subclass. Compared with template method, strategy uses delegation to vary the algorithm.
上一篇:design pattern notes [4] - chain of responsibility, visitor
下一篇:design pattern notes [6] - Observer