Re: Can use of singletons denote poor project design?



Daniel Parker wrote:
Phlip wrote:

Daniel Parker wrote:


I don't really see how there are any special issues for writing unit
tests for singletons.

Someone on comp.lang.c++ just pointed out, very politely, "I think you just
like using global variables because you're lazy".


Interesting. 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? Do you have a better
idea?

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


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.

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

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

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.


.



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)