Re: Can use of singletons denote poor project design?
- From: Phlip <phlip2005@xxxxxxxxx>
- Date: Fri, 24 Feb 2006 20:35:01 GMT
Daniel Parker wrote:
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?
Could you outline a test that changes the format, calls a method that relies
on formatted dates, and test its output is correct?
Could we then make the test just a tiiiiny bit simpler by taking out the
singleton and passing the date format directly?
To make the test case harder, suppose in System Q the CurrentTime is a
singleton (because, gee, time is a universal constant, so there's only one
of them). Now write a test that depends on a specific date to pass its
assertions.
I didn't say my method can detect any singleton that sucks. (I think I
didn't.) I implied my method can illustrate why some of them suck. There
might be other reasons that others of them suck too.
Those of us who recover legacy code can tell many stories of Singleton
abuse. If there was ever a candidate for time-travel to remove a chapter
from the Design Patterns book, Singleton would be it...
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
.
- Follow-Ups:
- Re: Can use of singletons denote poor project design?
- From: Daniel Parker
- Re: Can use of singletons denote poor project design?
- References:
- Re: Can use of singletons denote poor project design?
- From: Daniel Parker
- Re: Can use of singletons denote poor project design?
- Prev by Date: Re: Can use of singletons denote poor project design?
- Next by Date: Re: Can use of singletons denote poor project design?
- Previous by thread: Re: Can use of singletons denote poor project design?
- Next by thread: Re: Can use of singletons denote poor project design?
- Index(es):
Relevant Pages
|