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.

As with all Decorator design patterns, all other classes are derived from this abstract<br />

<strong>com</strong>ponent class. In the next section, you’ll see that all of the concrete <strong>com</strong>ponent<br />

classes are subclasses of the Auto class.<br />

Hybrid car classes concrete <strong>com</strong>ponent<br />

The four hybrid autos are placed into separate concrete <strong>com</strong>ponent classes that are all<br />

subclassed from the Auto class. The constructor function assigns a value to the<br />

information property, and the price( ) function returns a value representing the car’s<br />

price. In Examples 4-39 to 4-42, the captions are the filenames to use for saving each<br />

class.<br />

Example 4-39. Prius.as<br />

package<br />

{<br />

public class Prius extends Auto<br />

{<br />

public function Prius( )<br />

{<br />

information = "Toyota Prius Hybrid~\n";<br />

}<br />

override public function price( ):Number<br />

{<br />

return 21725.00;<br />

}<br />

}<br />

}<br />

Example 4-40. Mariner.as<br />

package<br />

{<br />

public class Mariner extends Auto<br />

{<br />

public function Mariner( )<br />

{<br />

information = "Mercury Mariner Hybrid~\n";<br />

}<br />

override public function price( ):Number<br />

{<br />

return 29225.00;<br />

}<br />

}<br />

}<br />

Example 4-41. Accord.as<br />

package<br />

{<br />

public class Accord extends Auto<br />

{<br />

166 | Chapter 4: Decorator Pattern

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

Saved successfully!

Ooh no, something went wrong!