-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Java Functional Programming
By :

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:
Rendering an image.
Updating the game.
Terminating the game when it is over.
This approach uses an abstract Game
class that contains a template method and abstract methods for the initialization, rendering, and updating steps. Its implementation follows where an infinite loop...
Change the font size
Change margin width
Change background colour