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.

Chapter CHAPTER 6 6<br />

Composite Pattern 6<br />

What we need to do is learn to work in the system, by<br />

which I mean that everybody, every team, every<br />

platform, every division, every <strong>com</strong>ponent is there not<br />

for individual <strong>com</strong>petitive profit or recognition, but for<br />

contribution to the system as a whole on a win-win<br />

basis.<br />

—W. Edwards Deming<br />

In a logically perfect language, there will be one word<br />

and no more for every simple object, and everything<br />

that is not simple will be expressed by a <strong>com</strong>bination<br />

of words, by a <strong>com</strong>bination derived, of course, from<br />

the words for the simple things that enter in, one word<br />

for each simple <strong>com</strong>ponent.<br />

—Bertrand Russell<br />

A <strong>com</strong>plex system that works is invariably found to<br />

have evolved from a simple system that works.<br />

—John Gaule<br />

What Is the Composite Pattern?<br />

The <strong>com</strong>posite pattern provides a robust solution to building <strong>com</strong>plexsystems that<br />

are made up of several smaller <strong>com</strong>ponents. The <strong>com</strong>ponents that make up the system<br />

may be individual objects or containers that represent collections of objects.<br />

Think of a car as a <strong>com</strong>plexsystem that is made up of several smaller <strong>com</strong>ponents.<br />

The car contains an engine, body, chassis, seats, tires, etc. For the sake of simplicity,<br />

let’s consider a tire as an indivisible or primitive object. A car would be <strong>com</strong>posed of<br />

four tires (in reality a tire contains several smaller <strong>com</strong>ponents such as hubcap, rim,<br />

tube, etc.). Similarly, a car contains one steering wheel. However, the engine contains<br />

several smaller <strong>com</strong>ponents such as cylinders, <strong>com</strong>pressor, radiator, etc. The<br />

engine is a <strong>com</strong>ponent of the car, but the engine itself is a collection of <strong>com</strong>ponents.<br />

We refer to a <strong>com</strong>ponent that is a collection of other <strong>com</strong>ponents as a <strong>com</strong>posite<br />

object. The beauty of the <strong>com</strong>posite pattern is that it allows clients to treat primitive<br />

204

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

Saved successfully!

Ooh no, something went wrong!