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

Reply via email to