Template Method(模板方法模式):一种面向对象的设计模式,在父类中定义算法的骨架(固定步骤),并把某些步骤延迟到子类去实现或覆盖,从而在不改变整体流程的情况下允许子类定制细节。(也常写作 Template Method Pattern)
/ˈtɛmpleɪt ˈmɛθəd/
We used the template method to keep the workflow consistent.
我们使用模板方法来保持工作流程一致。
The framework defines a template method that calls several hooks, so each subclass can customize validation and logging without changing the overall algorithm.
该框架定义了一个模板方法来调用多个钩子函数,因此每个子类都能在不改变整体算法的情况下自定义校验与日志记录。
template 意为“模板、固定格式”,method 意为“方法、步骤”。合在一起强调:先用“模板”规定流程结构,再用“方法/步骤”让子类补充或替换其中的可变部分。该术语在设计模式语境中因 GoF(四人帮) 的经典著作而广为流行。