Implementing the template pattern

The template pattern is based around the idea that certain problems have structures that are reflected in a core method. This method uses the same set of operations to perform a task. This can be seen in a loading task where the basic steps to load a container is essentially the same whether the container is a box or a truck.

The steps are the same, such as prepared item to be loaded, but the specific preparation will vary depending on the container. A box may require that the item be wrapped in paper while the truck may require the application of a plastic wrap.

We will use a game engine to illustrate this template. The basic steps include:

  1. Rendering an image.
  2. Updating the game.
  3. Terminating the game when it is over. ...

Get Learning Java Functional Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.