Re: Can use of singletons denote poor project design?



Daniel Parker wrote:

This discussion of a Singleton and related abuses is using the wrong
example.

I think it's using the right example.

A global that production code never writes on is mostly harmless. So it's
not the right example of the kind of Singleton that will irritate test
cases. Plenty of globals and Singletons won't (like I said before).

I suggested a test case that uses the defacto-global behind time() as a
little bit harder. You must wrap time() in a class, extract an interface,
write a mock time that returns a hard-coded, predictable time, then pass
the interface into everything that uses the time.

There - a test case has forced a global to become local.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
.



Relevant Pages

  • Re: Developing/compiling software
    ... What I take issue with is when people get obsessive about globals and think that it is somehow better to have functions called "SetUartTimeout" and "GetUartTimeout", doing nothing but accessing a static variable, ... The programming interface consists of a group of functions to do stuff like request, cancel, check, refresh timer etc and all you get back from or provide to the interface is a U8 timer handle or a status. ... Upper layer has the app call interface, ... The effect is really just a matter of making your access to global data a little more formalised and consistent, as well as tidying the data inside neat structs rather than in a loser pile. ...
    (comp.arch.embedded)
  • Re: globals again
    ... one of these functions needs the result of another function there seems ... If your callback function did the whole action (open file, ... you wouldn't need any globals. ...
    (comp.lang.c)
  • Re: Route-Maps and PIX
    ... off of the PIX with different globals. ... interface vlan 10 ... ip policy route-map netone ...
    (comp.dcom.sys.cisco)
  • Re: Pointers on pointers (ha...ha...ha..)
    ... Yes, I do use globals, but sparingly, and mostly for items of truly global scope. ... It also complicates code re-use, as globals are very much like tentacles that have to be amputated and then either cauterized or grafted. ... If a function has more than five arguments, it raises a red flag in my mind, and I reexamine the interface between the function and its caller. ...
    (comp.dsp)
  • Re: Hooking server DLL into PHP
    ... I was able to finally get ZEND interface/wrapper to work. ... structure with PHP, I can then write a write a C/C++ converter to a PHP ... I also want to study the "session" stuff to see if we can better interface ... a WCX script runs it inherits globals a User stricture, Msg structure, File ...
    (comp.lang.php)