Quantcast
Viewing all articles
Browse latest Browse all 11

Answer by Gort the Robot for Alternatives to the singleton pattern

If you are using a multiparadigm language like C++ or Python, one alternative to a singleton class is a set of functions/variables wrapped in a namespace.

Conceptually speaking, a C++ file with free global variables, free global functions, and static variables used for information hiding, all wrapped in a namespace, gives you nearly the same effect as a singleton "class".

It only breaks down if you want inheritance. I've seen a lot of singletons that would have been better off this way.


Viewing all articles
Browse latest Browse all 11

Trending Articles