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.

we can further reimplement it for the delegations the different concrete decorators use.<br />

Example 4-43 shows the abstract decorator class to be saved as Decorator.as.<br />

Example 4-43. Decorator.as<br />

package<br />

{<br />

//Abstract class<br />

public class Decorator extends Auto<br />

{<br />

override public function getInformation( ):String<br />

{<br />

return information;<br />

}<br />

}<br />

}<br />

Because the information variable is inherited from the Auto class, we need not redefine<br />

it here. It represents an abstract string.<br />

The options concrete decorators<br />

The concrete decorators generate the information that adds the information property<br />

and price value to each option. As a concrete <strong>com</strong>ponent is wrapped in each, the<br />

string data are added to any other strings that wrap the <strong>com</strong>ponent. So, when the<br />

getInformation( ) method launches, it first gets the delegated information from all<br />

other options and the concrete <strong>com</strong>ponent it wraps. In order not to get a huge string<br />

that we cannot unravel, a tilde (~) on the end of the added string will help separate<br />

all the different decorations. Examples 4-44 through 4-47 are labeled with the filenames<br />

used to save the class.<br />

Example 4-44. HeatedSeat.as<br />

package<br />

{<br />

public class HeatedSeats extends Decorator<br />

{<br />

private var auto:Auto;<br />

public function HeatedSeats(auto:Auto)<br />

{<br />

this.auto=auto;<br />

}<br />

override public function getInformation( ):String<br />

{<br />

return auto.getInformation( ) + " Heated Seats~";<br />

}<br />

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

{<br />

return 350.78 + auto.price( );<br />

}<br />

}<br />

}<br />

168 | Chapter 4: Decorator Pattern

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

Saved successfully!

Ooh no, something went wrong!