The template method pattern defines the steps of an algorithm in a template method that subclasses can inherit. Subclasses are allowed to override individual steps but not change the overall sequence of steps. For example, a template method for building a house defines steps like laying the foundation, adding pillars, and installing walls and windows, with concrete and wooden house subclasses implementing specific versions of each step while keeping the overall order. Similarly, a car template method defines steps like building the skeleton, installing the engine, and adding doors for subclasses like BMW and Ferrari cars.
2. Introduction
Take a look at the definition of a template
Template is a preset format, used as a starting point for a
particular application so that the format does not have to
be recreated each time it is used.
Template Method Pattern defines a sequence of steps of
an algorithm.
The subclasses are allowed to override the steps but not
allowed to change the sequence.
3. RealTimeExample-01
Template Method [Build
a House]
1)Building Foundation
2)Building Pillars
3)Building Walls
4)Building Windows
Concrete House
Wooden House
Foundation
Pillars
Walls
Windows
#3: template is a preset format, used as a starting point for a particular application so that the format does not have to be recreated each time it is used.