Re: Can use of singletons denote poor project design?




Phlip wrote:
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!

That sound's like a different test, testing a function with a specific
date format is a separate thing from testing the default 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".

There's a little bit global in everyone.

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

Who said anything about the DateFormat being a singleton? The default
DateFormat is 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.)

Yeah. That's why trading systems that have the concept of value date
typically allow the date to be set to a specified date.

Regards,
Daniel Parker
http://servingxml.sourceforge.net/

.



Relevant Pages

  • 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?
    ... relies on formatted dates, and test its output is correct? ... 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 ...
    (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)
  • SaveWorkbookAsToday()
    ... I have question about this script from Office VBA Macros you can use today ... ' The format to be used for the file names ... Dim DateFormat As String ... Dim Append As String ...
    (microsoft.public.excel.programming)