•You first identify the differences in the existing code and then separate the differences into new operations. Finally, you replace the differing code with a template method that calls one of these new operations. •To control subclasses extensions. You can define a template method that calls "hook" operations (see Consequences) at specific points, thereby permitting extensions only at those points.
Example•The Template Method defines a skeleton of an algorithm in an operation, and defers some steps to subclasses. •Home builders use the Template Method when developing a new subdivision. •A typical subdivision consists of a limited number of floor plans with different variations available for each. Within a floor plan, the foundation, framing, plumbing, and wiring will be identical for each house. Variation is introduced in the later stages of construction to produce a wider variety of models.
ExampleDaily routine of a worker.
Check list•Examine the algorithm, and decide which steps are standard and which steps are peculiar to each of the current classes.