Er. bah?!? 

 

Any var foo:DataManager = new DataManager() - - > will fail. As a properly
constructed singleton it won't compile! The constructor takes an argument
that is restricted to the package! The implementation that I provide you
will require all treatment to follow DataManager.getInstance() in order to
access the class. which will give you ---only one instance of the class---
globally in your application. If you had dropped my code in place of yours -
any 'new' declarations would prevent your application from compiling. This
isn't to prevent 'funny guys' from futzing with you code. it will  - through
an established pattern enforce everyone to utilize your DataManager in
exactly the same way. Before hitting the reply button - drop the code in
that I sent and hit the compile button and see what it does. Remember to put
your data manager into its own package - to prevent anyone from having
access to the SingletonEnforcer.

 

 

Rick Winscot

 

 

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of lytvynyuk
Sent: Wednesday, March 26, 2008 1:58 AM
To: [email protected]
Subject: [flexcoders] Re: Singletone class in Application and Modules !?

 

This will not change anything, still will be many times instantiated
"singleton" as in my example. Scope control is just to prevent funny
guys doing something like var Vasya = new DataManager();

--- In [email protected] <mailto:flexcoders%40yahoogroups.com> ,
"Rick Winscot" <[EMAIL PROTECTED]>
wrote:
>
> I just looked at your source. You forgot to control the scope! Your
> implementation should be:
> 
> package
> {
> public class DataManager
> {
> private static var singleton_:DataManager = new
> DataManager();
> 
> public function DataManager( enforcer:SingletonEnforcer ) {
> }
> 
> public static function getInstance():DataManager {
> 
> if ( singleton_ == null )
> singleton_ = new DataManager( new SingletonEnforcer );
> 
> return singleton_;
> } 
> }
> }
> 
> class SingletonEnforcer{}
> 
> 
> If you do this... it doesn't/won't matter where you instantiate it.
There
> can be only one - MUWUAHAHAHAA.
> 
> 
> Rick Winscot

 

<<image001.jpg>>

<<image002.jpg>>

Reply via email to