Sunday 25 June 2017

Software Engineering: Template Method Pattern

Behavioural Pattern - Template Method


Intent
Defines the skeleton of an algorithm in an operation, deferring some steps to sub classes. Template Method sub-classes redefine certain steps of an algorithm without changing the algorithms structure.

Why is this used?
This ensures the algorithm's structure stays unchanged, while sub classes provide some part of the implementation.

How is this applied?
  • An abstract class will contain the template methods
  • This will then be used as abstract versions of the operations used in the template method
  • There may well be many sub classes that want to implement the full set of operations in the template method


UML diagram representation 
https://sourcemaking.com/files/v2/content/patterns/Template_method_example-2x.png


More to follow...

No comments:

Post a Comment

Software Engineering: Bad Smells! (Smelly code)

Bad Smells! What are bad smells? This refers to any symptom in the source code of a program that possibly indicates a deeper problem.  ...