Template Method

This lesson discusses how algorithms with multiple steps can be made configurable by allowing subclasses to provide behavior for some of the steps.

What is it ?

A template can be thought of as a general or abstract structure that can be customized for specific situations. You may have used a template for writing your resume. The template would define the overall structure of the document and leave the details to be added in by the template user. The template method pattern is similar, it defines the skeleton or steps of an algorithm but leaves opportunities for subclasses to override some of the steps with their own implementations.

Formally, the pattern is defined as allowing subclasses to define parts of an algorithm without modifying the overall structure of the algorithm.

Get hands-on with 1400+ tech skills courses.