Re: Can use of singletons denote poor project design?




Phlip wrote:
[X-posted to comp.object and followups set]

John Fly wrote:

Right now I use [singletons] for :

Logging server : A central message storage and distribution to N number
of reports/logs)
Program State : Again a central point to keep track of program status.
Central Data representation

To pass fake data into the modules that use those systems, would you push
the fake data into the singleton, and let the modules use it?

That situation could be improved. In general, if the reason to declare a
Singleton is "because there's only one of them", then test cases always
violate this prerequisite because there's always many of them!

I don't really see how there are any special issues for writing unit
tests for singletons. For example, in Java, DateFormat.getInstance()
returns a default date format, which is a singleton object, there is
one instance of a default date format. Are you suggesting that you
would have difficulty testing whether this object satisfied its
specified properties? Why?

Regards,
Daniel Parker

.



Relevant Pages

  • Re: Can use of singletons denote poor project design?
    ... A central message storage and distribution to N number ... Program State: Again a central point to keep track of program status. ... "It is a truth universally acknowledged, that a singleton in possession ... ConcreteView class above depends on View, Model, and the ...
    (comp.object)
  • Re: Can use of singletons denote poor project design?
    ... Daniel Parker wrote: ... Program State: Again a central point to keep track of program status. ... "It is a truth universally acknowledged, that a singleton in possession ... Model, View, and Controller interfaces. ...
    (comp.object)