Re: Can use of singletons denote poor project design?
- From: Phlip <phlip2005@xxxxxxxxx>
- Date: Fri, 24 Feb 2006 21:33:39 GMT
Daniel Parker wrote:
Could you outline a test that changes the format, calls a method thatChanges the format to something other than what is required for the
relies on formatted dates, and test its output is correct?
default format? Why would you want to do that?
Is that a joke? To see if the target function respects the date format!
Presumably the default format depends on the default locale, so to test
that you could set the default locale and then test that the properties
of the format returned by getInstance() were as required.
Right. I admitted below this is an easy test case to write, even with
singleton abuse. You just said "change a global variable, call the
function, and expect it to read the global variable".
To make the test case harder, suppose in System Q the CurrentTime is aHuh???
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.
Suppose I want to illustrate how test cases can reveal problems with
singletons. Putting the date format into a singleton makes a test case
that's only a little bit icky.
So I want to pick a harder Singleton. I will pick one that emits the current
time. For example, in C, it looks like this:
time_t t = time(NULL);
That's a Singleton; each time you call it, it returns the current time.
Now write a test that does something with the time. Your target code now
can't use time(). (Unless you want to set the hardware clock during each
test, which is just wrong.)
--
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?
- From: Phlip
- 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
|