There are some ways to create singleton in ActionScript 3.0, though I prefer public "facade" with static initialization of internal class:
Internal class (it should be in the same package with "facade"):
But you could create 2 instances of AuthenticationManager right?
Yes, though you can't create AuthenticationManagerInstance instances, because it's internal, and the only instance of it could be referenced via AuthenticationManager.instance. Sure, constructor that throws exception could be added to the AuthenticationManager facade, but I don't see the reason. ;)
Ah but, what's stopping me from writing AuthenticationManager.instance = null;;)
Ok, you could change static property to static method with lazy initialization. ;)
I just came across this again, and I guess if you were storing a refence to your singleton you'd aslo have to type it as differenet to your public singleton class (or what you would think is the singleton class).i.e. although publically the Manager is the singleton, the return object needs the be type as Instance.var singleton:Instance = Manager.instance;
Post a Comment