Hooking It Up | 351
Hooking It Up
Controlling subclass extensions is one use for the Template Method. In discussing
applicability, the originators of the design pattern concepts (GoF) include what they
call a “hook” operation. The hook operation is placed into the template method to
allow extensions to the hook in the main algorithm.
For ActionScript 3.0 programmers, hook functions look exactly like the abstract
functions. That’s because ActionScript 3.0 has no real abstract functions, so we have
to keep in mind that the difference between hook operations and abstract ones is
that hook operationscanbe overridden, while abstraction operationsmustbe over-
ridden. This is where comment lines come in handy, as the following script shows:
//Abstract function
function doAbstract( ):void {}
//Hook function
function doHook( ):void {}
Neither the abstract function nor the hook function has to have any content. How-
ever, each is set up differently, and adding content to the hook operation provides a
way of setting up default conditions.
Figure 9-5. Video and tune player application