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.

etween the context classes and the strategy classes. The context classes are made up<br />

of a class and its subclasses. The context classes delegate actions to the strategy<br />

classes, made up of strategy interfaces and implementations of those interfaces. So<br />

the context classes delegate to the strategy classes.<br />

The delegation process begins in the main context class. It includes reference variables<br />

to the strategy interfaces. Methods in the context class do the actual delegation.<br />

The concrete context classes inherit the instance variables from the context<br />

class, and use those variables to specify which behaviors they want from the concrete<br />

strategies. Figure 11-2 shows a visual depiction of delegation.<br />

Figure 11-2. Delegation<br />

Request goes to Object Z, but Object Z farms<br />

it out (delegates it) to Delegate Beta<br />

If an instance of a class, which has a reference to a delegate that is called, is called,<br />

the delegate invokes the called method containing the encapsulated algorithm. So<br />

instead of inheriting the operation, the object can be said to have a method that handles<br />

a call.<br />

Minimalist Abstract State Pattern<br />

This first example cuts to the bare bones of a Strategy design pattern to reveal the<br />

structure of the design pattern. Each part is analyzed in terms of what it does for the<br />

overall pattern. This example should help make the structure clearer.<br />

You need to see the Strategy design pattern in a context where several different<br />

objects delegate behaviors to different delegates. (The second example provides this<br />

richer applicability.) In this minimalist example, you need to look at the points of<br />

delegation and how it all works. In Figure 11-3, following the listing, you will be able<br />

to see what looks like a web of intrigue. Not to worry; the illustration just shows the<br />

delegation work going on between the objects in the application.<br />

402 | Chapter 11: Strategy Pattern<br />

Aggregator<br />

Object Y Object Z<br />

Delegate<br />

Beta<br />

Delegate<br />

Delegate<br />

Alpha<br />

Delegate<br />

Gamma

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

Saved successfully!

Ooh no, something went wrong!