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.

oot<br />

<strong>com</strong>posite 1<br />

leaf 1<br />

leaf 2<br />

<strong>com</strong>posite 2<br />

leaf 3<br />

leaf 4<br />

leaf 5<br />

leaf 6<br />

It is important to note that the client sees only the interface defined by the Component<br />

class. The client doesn’t need to differentiate between <strong>com</strong>posite and leaf nodes, and<br />

isn’t tied to how the operation( ) method is implemented. It can simply call<br />

operation( ) on any leaf or <strong>com</strong>posite node and get consistent results.<br />

Accessing Child Nodes<br />

You may have noticed that we didn’t override and implement the getChild(n:int)<br />

method in the Composite class. However, this method’s very important to the <strong>com</strong>posite<br />

pattern, as it allows the client to develop a <strong>com</strong>posite structure by not declaring<br />

variables, as in the previous example. This ensures proper garbage collection when<br />

removing nodes. Garbage collection allows the application to recover memory and<br />

resources allocated to deleted nodes, and will be discussed in more detail later in the<br />

chapter. The getChild( ) method allows the client to access the children of any <strong>com</strong>posite<br />

node. The following getChild( ) method is implemented in the Composite class.<br />

override public function getChild(n:int):Component<br />

{<br />

if ((n > 0) && (n

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

Saved successfully!

Ooh no, something went wrong!