If we were to program two or three mapper classes, some commonality in the code would become apparent. The basic repeating algorithm structure for materializing an object is:
if (object in cache) return it else create the object from its representation in storage save object in cache return it
The point of variation is how the object is created from storage.
We will create the get method to be the template method in an abstract superclass AbstractPersistenceMapper that defines the template, and use a hook method in subclasses for the varying part. Figure 34.7 shows the essential design.
As shown in this example, it is common for the template ...