10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Figure 9-5. Video and tune player application<br />

Hooking It Up<br />

Controlling subclass extensions is one use for the Template Method. In discussing<br />

applicability, the originators of the design pattern concepts (GoF) include what they<br />

call a “hook” operation. The hook operation is placed into the template method to<br />

allow extensions to the hook in the main algorithm.<br />

For <strong>ActionScript</strong> <strong>3.0</strong> programmers, hook functions look exactly like the abstract<br />

functions. That’s because <strong>ActionScript</strong> <strong>3.0</strong> has no real abstract functions, so we have<br />

to keep in mind that the difference between hook operations and abstract ones is<br />

that hook operations can be overridden, while abstraction operations must be overridden.<br />

This is where <strong>com</strong>ment lines <strong>com</strong>e in handy, as the following script shows:<br />

//Abstract function<br />

function doAbstract( ):void {}<br />

//Hook function<br />

function doHook( ):void {}<br />

Neither the abstract function nor the hook function has to have any content. However,<br />

each is set up differently, and adding content to the hook operation provides a<br />

way of setting up default conditions.<br />

Hooking It Up | 351

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!