incubator-flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Heidegger ...@leichtgewicht.at>
Subject Re: [RT] From Singletons to Unit-testable code
Date Wed, 08 Feb 2012 04:42:44 GMT
On 08/02/2012 12:09, Alex Harui wrote:
>
> I don't understand what this does other than what mx.core.Singleton already
> does.
Actually there are two points: If you saw the small sample code: The use 
of mx.core.Singleton is not just a simple redirect,
    if (!_embeddedFontRegistry && !noEmbeddedFonts) {
         try {
            _embeddedFontRegistry = IEmbeddedFontRegistry( 
Singleton.getInstance("mx.core::IEmbeddedFontRegistry"));
        } catch (e:Error) {
            noEmbeddedFonts = true;
        }
    }
    return _embeddedFontRegistry;

This method contains a bunch of logic that shouldn't be static. In 
general I was referring not to Singletons in particular but to any 
static code except utils.

> The only issue I know of is there is no place in the application
> lifecycle that gives you a clean chance to swap out the implementation. That
> is much more easily fixed.

This second part is the reason I wrote this. I am all ears as to how 
this can be fixed more easily!

> And then there are some old singletons like EffectManager that still use
> static methods, which should be using Singleton instead.
I think that is something that the community easily can take care of.


> And then there is the whole debate about Singletons in general...
At the end of this refactoring all singletons would be gone.

yours
Martin.

Mime
View raw message