Chapter 25. The Template Pattern

In this chapter, we take up the Template pattern—a very simple pattern that you will discover you use all the time. Whenever you write a parent class and leave one or more of the methods to be implemented by derived classes, you are in essence using the Template pattern. This pattern formalizes the idea of defining an algorithm in a class, while leaving some of the details to be implemented in subclasses. In other words, if your base class is an abstract class, as often happens in these design patterns, you are using a simple form of the Template pattern. We note that Design Patterns refers to this as the Template Method Pattern, but we shorten the name in this chapter for convenience.

Motivation

Templates are so ...

Get Java™ Design Patterns: A Tutorial now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.