Re: Can use of singletons denote poor project design?




Andrew McDonagh wrote:
Daniel Parker wrote:

Do you think the designers of Java were lazy by
introducing the concept of a default DateFormat singleton object
accessible by a DateFormat.getInstance() member?

Not lazy...no

A default formatter is purely an optimisation. But we can still have
other DateFormats, its just that there's always the same single default
available.

Right, the default is global.

This discussion of a Singleton and related abuses is using the wrong
example.

I think it's using the right example.

What is lazy, is when people use singletons '..because its nicer than
passing the thing around...'.

Sometimes it is. Do you want the default DateFormat to be passed in
main()?

I've lost count of the number of times I've had the conversation with
developers who swear blind that global variable are the devil's spawn
and yet fail to see that a singleton is nothing more than a global variable.

Of course they're global, but Singleton's do offer some advantages over
naked global variables. Better packaging.

Regards,
Daniel Parker
http://servingxml.sourceforge.net/

.



Relevant Pages

  • Re: Singletons
    ... Besides the point that global variables are bad, ... we could do this with a Singleton or we can rearrange ... > IO streams, ... > default stdout" would return the standard output stream. ...
    (comp.object)
  • Re: Whats the best way to define global variable
    ... > can not understand the point put forward by Karl regarding "singleton surfes ... The purpose of a singleton is *not* to be a replacement of global variables. ... Karl Heinz Buchegger ...
    (comp.lang.cpp)
  • Re: Implementation of Singleton
    ... Thanks for all the input but it has now gone way over my head. ... have a basic understanding of classes and was hoping that I would be ... I know that the general concensus is that global variables are 'bad' ... >thanks to some initial reading and thinking re your singleton page. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Singleton Pattern
    ... but I don't think there's an ounce of truth in it. ... One practical problem with global variables (considered as a technology ... One solution to that is to use something like the Singleton pattern (or even ... what is a DBMS if it is not a chunk of data available to ...
    (comp.lang.java.programmer)
  • Re: Implementation of Singleton
    ... I know that the general concensus is that global variables are 'bad' ... and I will email you a zipped working sample of a singleton and its usage if that will help. ... Its always easier to "see" a working sample. ... private static readonly DebugLog m_Instance = new DebugLog; ...
    (microsoft.public.dotnet.languages.csharp)