Archive for Design Patterns

How to use the AS3-Layout-Framework

The AS3-Layout-Framework is basically very simple and easy to understand. It is based on one structural (Composite) and one behavioural (Strategy) pattern.

The composite pattern is used to compose objects into tree structures to represent part-whole hierarchies. Also it has the advantage to let clients treat individual objects and compositions of objects uniformly[GHJV95]. While updating all ILayoutComponents, a ILayoutContainer ( extends ILayoutComponent) lays out its subcomponents and a simple ILayoutComponent just handles its bounds ( Figure 1 shows the inheritance structure of the participants in more detail ).

The strategy pattern is used to encapsulate algorithms in objects with a well formed interface and lets the algorithm vary independently from clients that use it[GHJV95].
In the AS3-Layout-Framework the ILayout embodied the strategy pattern. This makes the creation of concrete layouts very simple and easy to plug in (f.e. GridLayout, FlowLayout).
Read more »

Actionscript 3.0 Layout Framework

During the last weeks I worked on an layout framework for actionscript 3.0 in my free time. I thought I would get some inspiration from the JAVA layout framework, and yes I got it.

Unfortunately the layout framework itself was overengineered and was not totally fulfilling my conceivabilities.

I just wanted a layout framework which is easy to extend, lightweight and fast with interfaces flexible enough for be used in other solutions( f.e. drag and drop).
Read more »

Addicted to MicroObservables

Very often it is necessary to use an obervable-pattern in its basic structure, which means that the observable notifies registered observers after its internal state has changed.

This implementation concept is very static and has the side effect that the observers are notified every time the model has changed regardless of which change they are interested in.

In this case it is recommended to use a more dynamic approach like an specific observable.

But if you only have one value in the model which changes, the MicroObservable structure could be very useful. Read more »

LoaderQueue with strategies

With the loader queue it is easy to load data (f.e images or xml) application wide in a priority queue. This version uses encapsulated ILoader implementations and is therefore easy to extend.

The loader queue has the following tokens:

  • priority
  • stop/pause/resume services
  • remove services
  • In addition it is possible to parametrize the loaded data with an anchor that could be of any type. This is very useful when images belong to specific objects (see code example).

    For a new need of a loader implementation a programmer just had to write a new specific loader strategy that implements ILoader.

    Basic implementations like a Loader and a URLLoader for loading Loader and URLLoader specific data can be found in the addicted2flash library. Read more »

    Lazy is not always bad…

    Lazy data-structures are structures that could be requested and are therefore not necessary loaded at request time.

    Besides "lazy" data retrieval another important aspect of these data-structures are often the possibility to cache executed requests. To reduce http-requests on server-side it's necessary to cache the results of former requests on client-side.

    To solve this problem a data-structure must be created on which specific ranges can be requested. Configured with a specific page size, data can be loaded with a constant size and requests therefore easily be cached. Read more »

    Extended Observer-Pattern

    The following post discusses an "extended" version of the Observer-Pattern.

    The intent of the observer pattern is often described as an one-to-many dependency.
    The key fact is that when one object changes its state, all listeners are notified about that change [GHJV95].

    There are only two relevant kinds of objects in this pattern, observers and an observable.

    An observable is basically an object that holds information on which other objects (observer) could be interested in.
    When the data-state of the observable has changed the observers are notified about the change.
    This kind of interaction is called publish-subscribe. The observable is the publisher of notifications. It sends out these notifications without having to know who its observers are[GHJV95]. Read more »