Design patterns implementation examples

Template method

Definition:

Defines a skeleton of an algorithm in an operation and allows subclasses to redefine certain steps of an algorithm without changing the algorithm's structure.


Example:

For instance CV form has blanks to fill in with your name, surname, work experience etc. CV structure does not change itself, only data is different. Another example instruction/algorithm of making coffee is the same as of making tea, only one step differentiates them. Instead of coffee you need to put tea bag in a cup than pour boiling water and add sugar to taste.


C++ code:

/src/templatemethod.cpp
Download source code

Template method UML class diagram:
Template method UML class diagram

Template method UML sequence diagram:
Template method UML sequence diagram