ActionScript 3.0 Design Patterns

(Chris Devlin) #1

58 | Chapter 1: Object-Oriented Programming, Design Patterns, and ActionScript 3.0


and ActionScript 3.0. However, the plan illustrates a basic truth about software in


general and web development in particular. You’re going to spend more time on


maintenance and changing a site than you are building it in the first place. As a


result, you need to plan for maintenance and extensibility, and not just to get things


working right in the first place.


Had the web site that had been planned for change been done with design patterns,


not only would it be able to adapt to change, we wouldn’t have to scrap the current


design and start all over from scratch to extend the site. That is, only part of the


planning process should address change of a static category. You also need to plan


for extending the site to incorporate more than what you originally planned to


change. That is, you may need to add new materials to change.


Planning Only for Maintenance


While the web site described asbuilt for changehas persisted, it has not evolved. The


site has been easy to maintain because its main function loads an image, a text file,


and menu items for a given product. By either changing the label on an existing but-


ton or adding a button, changing and adding products is pretty simple as well. So it


has a little extensibility in the sense that its not fixed to a single product.


However, the site really isn’t set up for robust extensibility. For instance, adding a


blog to the site or changing the way that the menus work would take the same


amount of re-structuring as it would to start from scratch. So, while changing prod-


ucts in the site is simple, changing the site is not. Structurally, the site looks some-


thing like Figure 1-9—The Big Function.


It doesn’t matter whether the big function is directly instantiated, gained through


inheritance, or a delegate of composition. It has no flexibility other than the parame-


ter to tell it what to place on the stage. If its algorithm is changed, it could wreck


havoc on its use. You can view it as tough and inflexible because it gets one job done


in one way. Alternatively, the big function can be seen as dainty and fragile because


of its dependency on a single routine, and because it is subject to freeze up when


Figure 1-9. The Big Function


function BigFunction (product)
{
load image in SWF
load text from text file
load menu items into array
load array into Combo box
}

The Big Function
Free download pdf