Singletons

From: Calum Grant (calumg_at_no.onetel.spam.com)
Date: 01/15/05


Date: Sat, 15 Jan 2005 15:17:35 GMT

I quite often see singletons in code, and I think they are overused.

Singletons have the disadvantage that everyone in the whole world has
access to that object, which is as bad as a global function. Anyone can
call a singleton and create havoc on it.

Singletons also introduce hard-coded dependencies that are difficult to
break if one wishes to change the environment or reuse some of the
classes in a different project.

Just because you call something a "singleton" instead of a global
variable does not make it a good pattern.

Singletons are lazy design, since "global scope" is too broad a scope
for most objects.

So my point is this: singletons should be discouraged, even banned.

Calum