ActionScript 3.0 Design Patterns

(Chris Devlin) #1

204


Chapter 6
CHAPTER 6


Composite Pattern 6


What we need to do is learn to work in the system, by
which I mean that everybody, every team, every
platform, every division, every component is there not
for individual competitive profit or recognition, but for
contribution to the system as a whole on a win-win
basis.


—W. Edwards Deming


In a logically perfect language, there will be one word
and no more for every simple object, and everything
that is not simple will be expressed by a combination
of words, by a combination derived, of course, from
the words for the simple things that enter in, one word
for each simple component.


—Bertrand Russell


A complex system that works is invariably found to
have evolved from a simple system that works.


—John Gaule


What Is the Composite Pattern?


The composite pattern provides a robust solution to building comple xsystems that


are made up of several smaller components. The components that make up the sys-


tem may be individual objects or containers that represent collections of objects.


Think of a car as a comple xsystem that is made up of several smaller components.


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


let’s consider a tire as an indivisible or primitive object. A car would be composed of


four tires (in reality a tire contains several smaller components such as hubcap, rim,


tube, etc.). Similarly, a car contains one steering wheel. However, the engine con-


tains several smaller components such as cylinders, compressor, radiator, etc. The


engine is a component of the car, but the engine itself is a collection of components.


We refer to a component that is a collection of other components as a composite


object. The beauty of the composite pattern is that it allows clients to treat primitive

Free download pdf