Re: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread Aaron Smith

i've actually had issues with this:::

say in one class I reference a singleton like this:
var s = MySingelton.getInstance();
s.doSomeMethod();

then in another class I reference it like this:
MySingleton.getInstance().doSomeMethod();


it created unexpected results where it wouldn't work using the first  
way. So our team has standardized always using the second method..


heres here I do singletons:

class SomeSingleton
{

//singleton instance
private static var inst:SomeSingleton;

//constructor
private function SomeSingleton()
{
init()
}

//initialize
private function init():Void
{
//some code
}

//singleton access
public static function getInstance():SomeSingleton
{
if( inst != null )
return inst;

return inst = new SomeSingleton();
}

//test method
public function someMethod():String
{
//some code
//call like:  SomeSingleton.getInstance().someMethod();
return "Called some Method";
}
}


On Feb 20, 2006, at 12:08 PM, Manuel Saint-Victor wrote:

Okay- so when I'm calling my getInstance(); shouldn't any info I  
retrieve
about properties on my Singleton be the same even if they are  
dynamically
updated. For example- I have a class that contains a Netstream  
object inside

my Singleton and I wold think that from any timeline I could create a
reference--> an instance of my class -->and then request  
myNetStream.time.
But this just gets me a bunch of zeros despite the fact that  
another tracer

from within that class is tracing out all kinds of other numbers for
myNetStream time's value.

I've been having several situations where I'm wondering if I'm losing
references when another object is calling my getInstance() or  
something

weird like that

M


On 2/20/06, Judah <[EMAIL PROTECTED]> wrote:


That's what I love about this list. The stuff I learn is  
invaluable. :)


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of  
Ian Thomas

Sent: Monday, February 20, 2006 12:52 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Re: When singletons go bad

If you use getInstance(), a constructor gets called - which is  
often handy

if you need to run any kind of initialisation code for your singleton
(that
you couldn't just do with initial property values).

If you just used statics, you might end up having to do something  
like:


public static function doSomething()
{
   if (!_initialised)
   {
  _initialiseMe();
   }
   // Do whatever this function is supposed to.
}

for every function that cared about the initialisation. Which is a  
pain.


I often pre-emptively use getInstance in case I need to go back  
and add

any
sort of initialisation to a class later on. If it's clearly a  
utility only
class (for example, string utilities, math utilities - just a  
collection

of
helper functions in a class) then I tend to use purely statics.

Cheers,
   Ian

On 2/20/06, JesterXL <[EMAIL PROTECTED]> wrote:


He can, but every other progammer (well, ok, mainly Java  
developers) are
familiar with the getInstance convention.  It clearly illustrates  
that

the

class is a Singleton.

I only use it when my boss says to; otherwise, static all the way  
baby.



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com




___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread Manuel Saint-Victor
Okay- so when I'm calling my getInstance(); shouldn't any info I retrieve
about properties on my Singleton be the same even if they are dynamically
updated. For example- I have a class that contains a Netstream object inside
my Singleton and I wold think that from any timeline I could create a
reference--> an instance of my class -->and then request myNetStream.time.
But this just gets me a bunch of zeros despite the fact that another tracer
from within that class is tracing out all kinds of other numbers for
myNetStream time's value.

I've been having several situations where I'm wondering if I'm losing
references when another object is calling my getInstance() or something
weird like that

M


On 2/20/06, Judah <[EMAIL PROTECTED]> wrote:
>
> That's what I love about this list. The stuff I learn is invaluable. :)
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas
> Sent: Monday, February 20, 2006 12:52 PM
> To: Flashcoders mailing list
> Subject: Re: [Flashcoders] Re: When singletons go bad
>
> If you use getInstance(), a constructor gets called - which is often handy
> if you need to run any kind of initialisation code for your singleton
> (that
> you couldn't just do with initial property values).
>
> If you just used statics, you might end up having to do something like:
>
> public static function doSomething()
> {
>if (!_initialised)
>{
>   _initialiseMe();
>}
>// Do whatever this function is supposed to.
> }
>
> for every function that cared about the initialisation. Which is a pain.
>
> I often pre-emptively use getInstance in case I need to go back and add
> any
> sort of initialisation to a class later on. If it's clearly a utility only
> class (for example, string utilities, math utilities - just a collection
> of
> helper functions in a class) then I tend to use purely statics.
>
> Cheers,
>Ian
>
> On 2/20/06, JesterXL <[EMAIL PROTECTED]> wrote:
> >
> > He can, but every other progammer (well, ok, mainly Java developers) are
> > familiar with the getInstance convention.  It clearly illustrates that
> the
> > class is a Singleton.
> >
> > I only use it when my boss says to; otherwise, static all the way baby.
> >
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread Judah
That's what I love about this list. The stuff I learn is invaluable. :)

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ian Thomas
Sent: Monday, February 20, 2006 12:52 PM
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Re: When singletons go bad

If you use getInstance(), a constructor gets called - which is often handy
if you need to run any kind of initialisation code for your singleton (that
you couldn't just do with initial property values).

If you just used statics, you might end up having to do something like:

public static function doSomething()
{
   if (!_initialised)
   {
  _initialiseMe();
   }
   // Do whatever this function is supposed to.
}

for every function that cared about the initialisation. Which is a pain.

I often pre-emptively use getInstance in case I need to go back and add any
sort of initialisation to a class later on. If it's clearly a utility only
class (for example, string utilities, math utilities - just a collection of
helper functions in a class) then I tend to use purely statics.

Cheers,
   Ian

On 2/20/06, JesterXL <[EMAIL PROTECTED]> wrote:
>
> He can, but every other progammer (well, ok, mainly Java developers) are
> familiar with the getInstance convention.  It clearly illustrates that the
> class is a Singleton.
>
> I only use it when my boss says to; otherwise, static all the way baby.
>
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread Manuel Saint-Victor
I'm not sure if it's really off topic but it's definitely one of those
questions that I've been pondering as I've been working with my mutant
Singleton/Static variable holder so thanks 4 bringing it up.
Scott - do you mind elaborating or pointing to a quick read on what you're
discussing there.


On 2/20/06, Scott Hyndman <[EMAIL PROTECTED]> wrote:
>
> The big difference is that singleton classes have an instance. By having
> an instance, the singleton class can inherited functionality as well as
> subclasses. There are many more benefits...but it really comes down to how
> you're using it. If you don't need inherited functionality, static classes
> are fine.
>
> Scott
>
> -Original Message-
> From:   [EMAIL PROTECTED] on behalf of Judah
> Sent:   Mon 2/20/2006 1:22 PM
> To: 'Flashcoders mailing list'
> Cc:
> Subject:RE: [Flashcoders] Re: When singletons go bad
>
>
> Slightly off the subject but why does he have to use getInstance()?
> Isn't there a way to use a singleton without calling getInstance? Why
> can't
> he directly use the class like this:
>
> import MyManager;
>
> MyManager.doSomething();
>
> The Math class, Delegate class and other classes let you use methods
> without
> calling getInstance() first.
>
> Judah
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Jack Doyle
> Sent: Monday, February 20, 2006 11:53 AM
> To: flashcoders@chattyfig.figleaf.com
> Subject: [Flashcoders] Re: When singletons go bad
>
> Just curious if this works better for you:
>
> private function MyManager() {
>  // constructor
>  return getInstance();
> }
>
> public static function getInstance() : MyManager{
>  if(_myManager == undefined){
>  _myManager = new MyManager();
>  _myManager.init();
>  }
>  return _myManager;
> }
>
> Sorry, I haven't had the time to follow the whole discussion, but I
> figured
> I'd throw this your way and see if it helps.
>
> Good luck.
>
> Jack
>
>
>
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
>
>
>
>
> ___
> Flashcoders@chattyfig.figleaf.com
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>
>
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread Ian Thomas
If you use getInstance(), a constructor gets called - which is often handy
if you need to run any kind of initialisation code for your singleton (that
you couldn't just do with initial property values).

If you just used statics, you might end up having to do something like:

public static function doSomething()
{
   if (!_initialised)
   {
  _initialiseMe();
   }
   // Do whatever this function is supposed to.
}

for every function that cared about the initialisation. Which is a pain.

I often pre-emptively use getInstance in case I need to go back and add any
sort of initialisation to a class later on. If it's clearly a utility only
class (for example, string utilities, math utilities - just a collection of
helper functions in a class) then I tend to use purely statics.

Cheers,
   Ian

On 2/20/06, JesterXL <[EMAIL PROTECTED]> wrote:
>
> He can, but every other progammer (well, ok, mainly Java developers) are
> familiar with the getInstance convention.  It clearly illustrates that the
> class is a Singleton.
>
> I only use it when my boss says to; otherwise, static all the way baby.
>
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread Scott Hyndman
The big difference is that singleton classes have an instance. By having an 
instance, the singleton class can inherited functionality as well as 
subclasses. There are many more benefits...but it really comes down to how 
you're using it. If you don't need inherited functionality, static classes are 
fine.

Scott

-Original Message-
From:   [EMAIL PROTECTED] on behalf of Judah
Sent:   Mon 2/20/2006 1:22 PM
To: 'Flashcoders mailing list'
Cc: 
Subject:    RE: [Flashcoders] Re: When singletons go bad


Slightly off the subject but why does he have to use getInstance()?
Isn't there a way to use a singleton without calling getInstance? Why can't
he directly use the class like this:

import MyManager;

MyManager.doSomething();

The Math class, Delegate class and other classes let you use methods without
calling getInstance() first. 

Judah

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jack Doyle
Sent: Monday, February 20, 2006 11:53 AM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] Re: When singletons go bad

Just curious if this works better for you:

private function MyManager() {
 // constructor
 return getInstance();
}

public static function getInstance() : MyManager{
 if(_myManager == undefined){
 _myManager = new MyManager();
 _myManager.init();
 }
 return _myManager;
}

Sorry, I haven't had the time to follow the whole discussion, but I figured
I'd throw this your way and see if it helps. 

Good luck.

Jack



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Re: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread JesterXL
He can, but every other progammer (well, ok, mainly Java developers) are 
familiar with the getInstance convention.  It clearly illustrates that the 
class is a Singleton.

I only use it when my boss says to; otherwise, static all the way baby.

- Original Message - 
From: "Judah" <[EMAIL PROTECTED]>
To: "'Flashcoders mailing list'" 
Sent: Monday, February 20, 2006 1:22 PM
Subject: RE: [Flashcoders] Re: When singletons go bad



Slightly off the subject but why does he have to use getInstance()?
Isn't there a way to use a singleton without calling getInstance? Why can't
he directly use the class like this:

import MyManager;

MyManager.doSomething();

The Math class, Delegate class and other classes let you use methods without
calling getInstance() first.

Judah

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jack Doyle
Sent: Monday, February 20, 2006 11:53 AM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] Re: When singletons go bad

Just curious if this works better for you:

private function MyManager() {
// constructor
return getInstance();
}

public static function getInstance() : MyManager{
if(_myManager == undefined){
_myManager = new MyManager();
_myManager.init();
}
return _myManager;
}

Sorry, I haven't had the time to follow the whole discussion, but I figured
I'd throw this your way and see if it helps.

Good luck.

Jack



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com 

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


RE: [Flashcoders] Re: When singletons go bad

2006-02-20 Thread Judah

Slightly off the subject but why does he have to use getInstance()?
Isn't there a way to use a singleton without calling getInstance? Why can't
he directly use the class like this:

import MyManager;

MyManager.doSomething();

The Math class, Delegate class and other classes let you use methods without
calling getInstance() first. 

Judah

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jack Doyle
Sent: Monday, February 20, 2006 11:53 AM
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] Re: When singletons go bad

Just curious if this works better for you:

private function MyManager() {
 // constructor
 return getInstance();
}

public static function getInstance() : MyManager{
 if(_myManager == undefined){
 _myManager = new MyManager();
 _myManager.init();
 }
 return _myManager;
}

Sorry, I haven't had the time to follow the whole discussion, but I figured
I'd throw this your way and see if it helps. 

Good luck.

Jack



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


[Flashcoders] Re: When singletons go bad

2006-02-20 Thread Jack Doyle
Just curious if this works better for you:

private function MyManager() {
 // constructor
 return getInstance();
}

public static function getInstance() : MyManager{
 if(_myManager == undefined){
 _myManager = new MyManager();
 _myManager.init();
 }
 return _myManager;
}

Sorry, I haven't had the time to follow the whole discussion, but I figured
I'd throw this your way and see if it helps. 

Good luck.

Jack



___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com