Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Employing Flexibility in the Template Method Now that you have a better idea of how the Template Method design pattern's struc- ture works, let's see how it can be usefully employed. In this next example, you'll see an implementation that uses the same template method for two different concrete classes. Figure 9-4 shows the class diagram: ShedMaker templateMethod() doDesign() determineSupplies() storeTools() doDesign() determineSupplies() storeTools() WoodShed doDesign() determineSupplies() SteelShed doDesign() determineSupplies() Figure 9-4. Template method with two concrete classes The main abstract class, ShedMaker , includes three operations in the templateMethod( ) function. Two are abstract and will be overridden by the subclasses where the details