Addicted to MicroObservables
August 26th, 2008 • Actionscript 3.0, Design Patterns
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.
To be more generall, this implementation is basically a rudimentary way of an generic remote proxy. This comparison leaks in some way, but point out the advantages.
The following uml-diagram shows the dependencies between the participants:

After the value is available (setted from outside) the MicroObservable notifies all registered MicroObservers with its internal notifyObservers() method.
public function set value( value: * ): void { _value = value; _hasChanged = true; notifyObservers(); }
The classes can be found in the addicted2flash library.
Try this,
public function set value( value: * ): void
{
if(_value != value)
{
_value = value;
_hasChanged = true;
notifyObservers();
}
}
Observer pattern is very flexible.