Archive

Archive for July, 2007

The ActionScript 3.0 Flyweight Saga: Part II Extrinsic States

Extrinsic States
In the first part of the Flyweight Saga, I had the idea that a Flyweight design pattern would be a good idea because it would be useful for cranking out buttons on the stage. However, the comments by the readers have led me to reconsider that idea; so it’s back to the drawing board. This revised Flyweight is going to focus on adding an extrinsic state parameter. Also, I got rid of all but one of the concrete Flyweights and am now down to the FlyButton class only in order to focus on extrinsic states.

Keep in mind that this process is a matter of working out the specific sense of a Flyweight pattern more than it is to show the optimum example. In going over some Flyweight materials from MIT, they suggested having a grasp on other, simpler patterns like the Observer and even MVC before tackling the Flyweight. This was both comforting and worrisome!

Extrinsic State Parameter

To get back on track (somewhat), this new Flyweight includes a parameter for extrinsic states in the Flyweight interface. Because the state is extrinsic, it changes with the Flyweights context. As discussed briefly in Part I of this saga, the extrinsic state changes with the context while the intrinsic state does not. Thus, the extrinsic state is not shareable (a shared object) and the intrinsic is. A concrete class can be sharable or not, but it cannot be if it does not store the intrinsic state. However, both sharable and non-sharable concrete Flyweights can exist. The following summary might be helpful.
Extrinsic state

    Cannot be shared
    Depends on flyweight’s context
    Client is responsible for supplying extrinsic state when needed

Intrinsic state

    Can be shared
    Stored (inherent) in the flyweight
    Does not depend flyweight’s context

Read more…

Share

ActionScript 3.0 Design Patterns book is now out!

All 532 pages Now Available
ActionScript 3.0 Design Patterns has been published and is now available anywhere you buy books. Amazon.com has indicated 328 pages, but the actual page count is 532 pages. So just figure you get an extra 200 pp free!

Free Sample Chapter
You can get a free sample chapter at: Decorator Pattern from O’Reilly.

Table of Contents
Check out the Table of Contents TOC to see the topics and design patterns covered. Examples can be written in Flex or Flash CS3.

Share