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.
阅读(716) | 评论(0) | 转发(0) |