Template Method Design Pattern - 模板方法设计模式

来源:互联网 发布:软件部门应聘 编辑:程序博客网 时间:2024/05/21 09:27

UML图示:

用途:

Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Let subclasses redefine certain steps of an algorithm without changing the algorithm's structure.

 

即:定义某类操作的算法框架,将不变行为放在父类实现;而将可变行为定义在父类,由子类去实现。如此以来,一不会改变整个操作流程,二利用多态实现代码复用的最大化。