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.

Decorating with Multiple Properties<br />

Multiple properties and methods are not difficult to add to <strong>com</strong>ponents, and the<br />

same is true for decorator classes. Instead of a single property and method, you do<br />

essentially the same thing using multiple methods and classes. Example 4-20 shows<br />

the abstract Decorator class, subclassed from the Component class. Save the script as<br />

Decorator.as.<br />

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

package<br />

{<br />

//Abstract class<br />

public class Decorator extends Component<br />

{<br />

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

{<br />

return soul;<br />

}<br />

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

{<br />

return goodness;<br />

}<br />

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

{<br />

return vice;<br />

}<br />

}<br />

}<br />

As a subclass of the Component class, this Decorator abstract class does nothing more<br />

than re-implement the getter functions—one returning a string, and the other two<br />

returning a number. The properties that are to be returned were originally defined as<br />

properties in the Component class, and as a subclass of Component, the Decorator class<br />

doesn’t have to re-implement them. However, as you’ve seen in previous examples,<br />

the getter functions are re-implemented. The only difference is that there are more of<br />

them. However, the process and logic are the same.<br />

Multiple Method Concrete Decorations<br />

When it <strong>com</strong>es to the concrete decorations in this example application, we’re going<br />

to see something slightly new. First, take a look at example 4-21. It’s a generic example<br />

and should not be placed in as actual code. Just look at it. Several actual concrete<br />

elements with working code will replace generic values.<br />

Decorating with Deadly Sins and Heavenly Virtues | 151

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

Saved successfully!

Ooh no, something went wrong!