ActionScript 3.0 Design Patterns

(Chris Devlin) #1

PART III


III.Structural Patterns


True ornament is not a matter of prettifying externals.
It is organic with the structure it adorns, whether a
person, a building, or a park.
—Frank Lloyd Wright
The importance of certain problems concerning the
facts will be inherent in the structure of the system.
—Talcott Parsons (20th Century Sociologist)
If the structure and the program components were
well chosen, then often many of the constituent
instructions can be adopted unchanged.
—Niklaus Wirth

Structural patterns are strategies that use classes and objects to build larger struc-


tures. In part, the process entails using abstract classes as interfaces, with derivative


classes making up the larger structures. Using both inheritance and composition, the


Structural patterns provide rich flexibility for designing applications. The class pat-


terns tend toward using inheritance in generating larger structures, and object struc-


tures tend to be built using composition. However, both kinds of approaches have


the same general approach. Figure Part III-1 illustrates the overall Structural pattern.


As a mental image, you can think of constructing applications with Structural pat-


terns as pulling parts out of different bins. The bins represent different class exten-


sions and object compositions. The structure itself is built from the parts gathered


from the bins, but it becomes a new phenomenon distinct from the parts used to


build it.


This section examines three different Structural patterns. First, the Decorator pat-


tern adds responsibilities to an object. A single component iswrappedwith new


functionalities and properties while remaining fundamentally unchanged as far as its


internal structure is concerned. The Adapter pattern provides a way for two unre-


lated interfaces to work together. When adding a new object to an otherwise incom-


patible structure, the Adapter is an alternative to rebuilding an application from


scratch to accept a new feature. You will find out how to create Adapter applications

Free download pdf