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.

Examples 4-18 and 4-19 provide the concrete <strong>com</strong>ponents for Dick and Jane classes.<br />

Each class just needs a string value for soul and numeric values for goodness and<br />

vice—all inherited properties from the Component class. Save Example 4-18 as Dick.as,<br />

and Example 4-19 as Jane.as.<br />

Example 4-18. Dick.as<br />

package<br />

{<br />

public class Dick extends Component<br />

{<br />

public function Dick( )<br />

{<br />

soul = "Dick's soul\n";<br />

goodness=0;<br />

vice=0;<br />

}<br />

}<br />

}<br />

Example 4-19. Jane.as<br />

package<br />

{<br />

public class Jane extends Component<br />

{<br />

public function Jane( )<br />

{<br />

soul = "Jane's soul\n";<br />

goodness=0;<br />

vice=0;<br />

}<br />

}<br />

}<br />

These concrete <strong>com</strong>ponent classes are exactly like the previous examples we’ve<br />

examined, except we have two instead of one. Furthermore, instead of using a single<br />

string variable, two additional numeric variables are added, along with their assigned<br />

values. Otherwise, they’re just the same.<br />

In these two concrete classes, the properties are inherited directly from the abstract<br />

Component class. No overrides or other special adjustments are needed. This is<br />

because the Dick and Jane classes are <strong>com</strong>ponents, both to be decorated by the decorator<br />

classes. The overrides that generate unique methods and characteristics for the<br />

concrete decorators are ac<strong>com</strong>plished by the decorator classes. Therefore, overrides<br />

by the concrete <strong>com</strong>ponent classes are unnecessary.<br />

150 | Chapter 4: Decorator Pattern

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

Saved successfully!

Ooh no, something went wrong!