V2EX  ›  英汉词典

Template Method

释义 Definition

Template Method(模板方法模式):一种面向对象的设计模式,在父类中定义算法的骨架(固定步骤),并把某些步骤延迟到子类去实现或覆盖,从而在不改变整体流程的情况下允许子类定制细节。(也常写作 Template Method Pattern

发音 Pronunciation

/ˈtɛmpleɪt ˈmɛθəd/

例句 Examples

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.
该框架定义了一个模板方法来调用多个钩子函数,因此每个子类都能在不改变整体算法的情况下自定义校验与日志记录。

词源 Etymology

template 意为“模板、固定格式”,method 意为“方法、步骤”。合在一起强调:先用“模板”规定流程结构,再用“方法/步骤”让子类补充或替换其中的可变部分。该术语在设计模式语境中因 GoF(四人帮) 的经典著作而广为流行。

相关词 Related Words

文学与作品 Literary Works

  • Design Patterns: Elements of Reusable Object-Oriented Software(Gamma, Helm, Johnson, Vlissides)
  • Head First Design Patterns(Freeman & Robson)
  • Refactoring to Patterns(Joshua Kerievsky)
  • Agile Software Development, Principles, Patterns, and Practices(Robert C. Martin)
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1937 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 11ms · UTC 13:04 · PVG 21:04 · LAX 05:04 · JFK 08:04
♥ Do have faith in what you're doing.