Yepper - it will compile. The parameter passed to the constructor helps
limit scope through package/class visibility. 

 

Rick Winscot

 

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of dbronk
Sent: Wednesday, March 26, 2008 9:23 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Singletone class in Application and Modules !?

 

Will this even compile? Your static variable singleton_ is declared
with new DataManager(). But your constructor requires a parameter. 
If this was just a typo in the post and it was declared passing in
SingletonEnforcer, then you should not even need the if null check in
getInstance as it will always have been created, correct?

Also, when I had this happening, I tried making sure that the
application had instantiated it first thinking the same thing. I
could still get a different instance in the modules. At least I
thought I made a point to instantiate in the app first, but it now has
been a couple months and I may not be remembering all my tests correctly.

Dale

--- In flexcoders@yahoogroups.com <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
> 
> 
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ]
On
> Behalf Of lytvynyuk
> Sent: Wednesday, March 26, 2008 1:28 AM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] Re: Singletone class in Application and Modules !?
> 
> I figured out the case. I, actually, made first instance in another
module
> not in main App. 
> Conclusion is: if you make instance in your main app - everything works
> fine. 
> If you did it in one of modules, this and all others will get new
instances.
> Very easy to see when put trace("BLAH") in the constructor. PS. do not
> include your class, which suppose to be singleton in you main
application,
> and then it will fail.
> 
> test included >> testSingleton.zip 
> 
> >
> > I beg to differ. I had setup my app thinking this to be true. When I
> > did this the module would get it's own, and very different, instance
> > of my singleton. I had to change the way I did things so what I do
> > now is upon loading my module, the main app then sets the singleton
> > into the module. I don't have my example code anymore, but it was
> > quite easy to produce the results.
> > 
> > Maybe it has to do with the way I compiled my module???? I compiled
> > my application with "-link-report=c:\app\encoreNG.link.report.xml" and
> > my module with "-load-externs=c:\app\encoreNG.link.report.xml". Not
> > sure if that has anything to do with it. Also, when I had this coded
> > I was on Flex 3, Beta 3 and have not retested with Flex 3 GA.
> > 
> > Dale
>

 

<<image001.jpg>>

<<image002.jpg>>

Reply via email to