Re: Singleton --- almost

From: Ryan Stewart (zzanNOtozz_at_gSPAMo.com)
Date: 03/09/05


Date: Tue, 8 Mar 2005 18:16:10 -0600


"John C. Bollinger" <jobollin@indiana.edu> wrote in message
news:d0hpl6$24n$1@rainier.uits.indiana.edu...
> I think Singleton is the single most misused design pattern in the current
> lexicon.
>
> I have at times heard or received comments that a class should be made a
> Singleton because only one instance is needed: THIS IS TOTALLY WRONG. In the
> first place, whether more than one instance might be *needed* is a completely
> different question from whether more than one instance should be *allowed*.
> Secondarily, I have little faith in assertions such as I described actually
> being accurate. It is my opinion that they tend to arise when people look for
> design patterns to apply, instead of trying to judge which design patterns are
> appropriate (perhaps a subtle distinction). The structure of the Singleton
> pattern is relatively easy to understand, which makes the pattern low-hanging
> fruit for pattern seekers.
>
> I am in agreement with other respondents that it is frequently best to simply
> create only those objects you need, without applying special structure to your
> classes. It may be useful to have a registry of particular objects used by
> your application; with a Singleton, the class itself serves as such a
> registry, but there is no special need for that. In fact, unless there is a
> particular need that the same object be used everywhere throughout the
> application, I would do away with any central registry.
>
What about a situation where you frequently use a stateless object to service
other objects? If the service object is not a singleton, hundreds or thousands
of them might be created and discarded in a short time. As a singleton, only the
one instance is ever created, and this is perfectly sufficient. Would you
consider this a valid reason to use the pattern?



Relevant Pages

  • Re: Singleton --- almost
    ... >>design patterns to apply, instead of trying to judge which design patterns are ... The structure of the Singleton ... It may be useful to have a registry of particular objects used by ... objects using the class to adopt an effective usage strategy. ...
    (comp.lang.java.programmer)
  • Re: RMI, singletons and multiple classloaders in Weblogic
    ... > of ClassLoaders for efficient implementation. ... > the banes of Java Singleton implementations. ... > pattern, that registry is within the class itself. ...
    (comp.lang.java.programmer)
  • Re: RMI, singletons and multiple classloaders in Weblogic
    ... With the Singleton ... >>pattern, that registry is within the class itself. ... GoF pattern: I'd nominate one of "Decorator", "Template Method", or ... "Factory / Factory Method" for that honor. ...
    (comp.lang.java.programmer)
  • Re: Singleton Pattern
    ... I have a question about singleton pattern. ... the Plant class is now coupled to LightSourceSingletonFactory and the ... LightSource interface. ...
    (comp.lang.java.programmer)
  • Re: Singleton VS Static Class
    ... I dislike the classical version of the Singleton pattern. ... the problem had shown the need for a special instance which should be easiliy ... nothing wrong with globals if handled correctly), ...
    (comp.lang.java.programmer)