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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 9-3. Hollywood principle<br />

Minimalist Example: Abstract Template Method<br />

Even though it may not make a lot of sense to use a Template Method design pattern<br />

when you have only a single subclass, doing so helps reveal the design pattern’s structure.<br />

So, in this minimalist example, you should be able to easily see the underlying<br />

structure used in the Template Method. We don’t need much, just two main classes:<br />

• Abstract class with the algorithm for the template method<br />

• At least one concrete class as a subclass of the abstract class<br />

Look for the operations that will be detailed by the subclasses, and the one operation<br />

that will be constant throughout the subclasses.<br />

Bare Bones Template Method<br />

Examples 9-1 and 9-2 show the two classes we need to get started with this simple<br />

but useful pattern. Save each class using the caption name as the filename.<br />

Example 9-1. AbstractClass.as<br />

package<br />

{<br />

//Abstract Class<br />

class AbstractClass<br />

{<br />

public final function templateMethod( ):void<br />

{<br />

primitiveA( );<br />

primitiveB( );<br />

338 | Chapter 9: Template Method Pattern<br />

Abstract Class<br />

template method()<br />

operationA()<br />

operationB()<br />

(locked algorithm)<br />

operationA()<br />

operationB()<br />

Concrete Class<br />

operationA()<br />

operationB()<br />

Responsible for order of<br />

operations in algorithm<br />

Tucked inside of<br />

locked algorithm<br />

Concrete Class<br />

operationA()<br />

operationB()<br />

Specification of operations, but not algorithm.<br />

Calls from template method, but not subclass

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

Saved successfully!

Ooh no, something went wrong!