CBR Logo


CBR*Tools Documentation


B1.Abstract Factory


B2.Adapter


B3.Chain of Responsibility


B4.Composite


B5.Facade


B6.Factory Method


B7.Iterator


B8.Prototype


B9.Strategy


B10.Template Method


Logo of Inria at Sophia Antipolis


French flag - link to the french documentation


Return to the Action AID
main page

Annex B: Design Patterns

B10.Template Method

Description

When an algorithm has variable stages according to the context, this pattern proposes to delegate to subclasses the concrete realisation of these stages.

Structure and Components

Structure and Components of the Tempate Method design pattern

Structure and Components of the Template Method design pattern

  • Protocol defines the interface of the algorithm and call methods for the realisation of certain variable stages,
  • Protocol1 and Protocol2 implement the missing stages in the algorithm,
  • ProtocolClient initiates the execution of the algorithm.

Collaborations

The client launches the algorithm in which the invariant part is executed directly, whereas the variable stages are carried out in a specific way by the operations defined in a concrete class.

Collaborations of the Tempate Method design pattern

Collaborations of the Template Method design pattern

Strengths and Weaknesses

Plus sign allows to establish once and for all the structure of an algorithm and invariable parts which will be shared,

Plus sign allows to personalise certain parts of an algorithm in subclasses,

Minus sign the stages delegated to the subclasses must be selected carefully to be really useful,

Minus sign problem of verifivation of the assumptions made by the base class which can be violated by the implementation in a subclass.

Use in CBR*Tools

This pattern is used in the phases of reasoning and the protocol of indexing in order to offer open algorithms and protocols.




Valid XHTML 1.0! Valid CSS! Brigitte Trousse
Last modified: Fri Sep 28 13:52:40 MEST 2001