Re: Can use of singletons denote poor project design?



Daniel Parker wrote:

Could you outline a test that changes the format, calls a method that
relies on formatted dates, and test its output is correct?

Changes the format to something other than what is required for the
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 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.

Huh???

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!!!
.



Relevant Pages

  • Re: Can use of singletons denote poor project design?
    ... Changes the format to something other than what is required for the ... To see if the target function respects the date format! ... singleton (because, gee, time is a universal constant, so there's only ... Who said anything about the DateFormat being a singleton? ...
    (comp.object)
  • Re: Can use of singletons denote poor project design?
    ... returns a default date format, which is a singleton object, there is ... Could you outline a test that changes the format, ... I implied my method can illustrate why some of them suck. ...
    (comp.object)
  • Re: Can use of singletons denote poor project design?
    ... returns a default date format, which is a singleton object, there is ... one instance of a default date format. ... Presumably the default format depends on the default locale, ...
    (comp.object)
  • Re: When is it appropriate to use static methods?
    ... I am using the following format to create my singleton: ... > namespace Company.TWS.BusinessObject ... The normal singleton pattern would have the _twsDS and twsDS ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: sql works in query - refuses to work in module
    ... | properly formed SQL. ... It relies on Access being able to find the form ... It relies on Access dealing with zero length strings and nulls ... You have to remember abount right date format within ##, ...
    (comp.databases.ms-access)