advertisement

Article:
  Using the Singleton Pattern
Subject:   Singleton Considered Harmful
Date:   2003-08-29 05:15:05
From:   diegof79
Response to: Singleton Considered Harmful

I agree with your comment, for more information on why the singleton pattern is considered harmful see:


http://www.c2.com/cgi/wiki?SingletonsAreEvil
http://www.c2.com/cgi/wiki?AnotherJavaSingletonProblem

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • Singleton Considered Harmful
    2003-09-09 00:20:22  anonymous2 [Reply | View]

    hi,

    From an enterprise application point of view,
    There are often services which are deployed as singletons. For eg, JNDIlookUpDirectory of the application.

    Only one instance manages the addresses in the directory.

    The problem wiyth singleton, classes, is that they cannot be deployed in a clustered environment.

    If deployed, only one instance of the clsuter will have this singletton class instantiated else it will fail.

    In cases, where scalablity and failover is desired, singleton pattern offers a bottleneck.

    Is there any work around for such singletons, already existing in this existing application.

    Regards,
    Dimple
  • Singleton Considered Harmful
    2003-08-29 11:37:24  jimothy [Reply | View]

    Thanks for the links. The first link (SingletonsAreEvil) linked me to an IBM developerWorks article, which it turns out I had previously read before, and formed much of the basis for what I wrote in my post.

    It's a good article that explains the pitfalls of singletons, how to structure your code to avoid using singletons, and the benefits of doing so. I recommend everyone who read this O'Reilly article also take a look at a counterpoint: http://www-106.ibm.com/developerworks/webservices/library/co-single.html

    My advice is not to use any pattern blindly; the GoF describes the appropriate contexts and forces for using a particular pattern. The Singleton pattern is especially easy to abuse, because it is so simple conceptually. But no pattern should be taken as the Gospel.