Template Method
Implementation
Three implementation issues are worth noting:
- Using C++ access control.
In C++, the primitive operations that a template method calls can be
declared protected members. This ensures that they are only called by
the template method. Primitive operations that must be overridden are
declared pure virtual. The template method itself should not be
overridden; therefore you can make the template method a nonvirtual
member function.
- Minimizing primitive operations.
An important goal in designing template methods is to minimize the
number of primitive operations that a subclass must override to flesh
out the algorithm. The more operations that need overriding, the more
tedious things get for clients.
- Naming conventions.
You can identify the operations that should be overridden by adding a
prefix to their names. For example, the MacApp framework for Macintosh
applications prefixes template method names with ``Do-'':
``DoCreateDocument'', ``DoRead'', and so forth.