Design Patterns Series 11 - Template Method Pattern
This post and the next will be about two patterns that give you clever ways of dealing with adapting the process of creating objects: The Template Method Pattern and Builder Pattern . The Template Method Pattern: The Template Method pattern lets sub-classes redefine the steps involved in creating an object.The Template Method will " define the skeleton of an algorithm in an operation, deferring some steps to sub-classes. Template Method lets sub-classes redefine certain steps of an algorithm without changing the algorithm structure. " You should use the Template Method pattern when you have an algorithm that is made of multiple steps, and you want to be able to customize some of those steps. Note That if you want to rewrite everything from scratch every time - if every step has to be customized by writing it from scratch - then you have no need of a template. Only if you have steps that are shared by various implementations of the algorithm do you need to work w...