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.

to inspect. So, you’re going to need special instructions for the first item in the outline<br />

depending on the vehicle.<br />

This chapter contains two different types of references to “template<br />

method.” A reference to the Template Method design pattern will<br />

have the first letter of each word capitalized. The template method is<br />

also a reference to a method (function), and that reference will use<br />

lowercase for both words.<br />

For the second step, navigation in a car requires getting on the road, making all the<br />

correct turns, and using the right streets. This can be tricky at times, and the driver<br />

may want to check on traffic reports to avoid congestion or road repairs. Depending<br />

on the circumstances, a boat trip can be anything from a quick trip across a lake to a<br />

<strong>com</strong>plexnavigation through shoals, shallows, and currents. Finally, navigating an<br />

airplane can be a simple straight flight on a clear day to an IFR (Instrument Flight<br />

Rules) flight requiring knowledge of several different navigation instruments in<br />

cloudy weather. Like the first step, this too will require specialized instructions.<br />

Finally, you’ve got the cup of coffee you drink on the way to work. That’s pretty<br />

much the same no matter what kind of transportation you use. You’d use the same<br />

kind of travel container with all three modes of transportation, and you’d have to<br />

take care not to spill coffee in your lap. Unlike the first two sets of instructions that<br />

differ for each mode of transportation, this last one’s going to be the same for all<br />

three vehicles.<br />

Making a template for this set of circumstance requires a loosely crafted method for<br />

the first two items and a concrete one for the last. Using the Template Method<br />

design, each of the three functions would be placed in a method so that the sequence<br />

of the steps would be preserved no matter what. The method containing the ordered<br />

functions is the template method—a method to preserve the sequence. Here’s what it<br />

would look like in a rough pseudocode:<br />

//Within an abstract class<br />

//This the the Template Method<br />

final function templateMethod( )<br />

{<br />

prepareTransportation( );<br />

navigatVehicle( );<br />

drinkCoffee( );<br />

}<br />

//Abstract functions<br />

function prepareTransportation( ):void<br />

{<br />

//nothing here<br />

}<br />

332 | Chapter 9: Template Method Pattern

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

Saved successfully!

Ooh no, something went wrong!