Patterns for Replacing Global Variables - Replace Global(s) with Singleton

Replace Global(s) with Singleton

I'm not sure this is a superior solution as it replaces many globals with one global structure. Granted you can add access control, but to what effect since you must grant global read/write, also it is difficult to enforce semantic meaning/intent.

I'd go as far as to say that using singletons is really no better than having a naming convention for globals.

Additionally, it makes code difficult to test since many singletons in the OO world are typically self configuring and are referenced deep down inside private methods. How does one test code that gets it's database connection inside a private method from a singleton ? (Don't laugh, it happens all the time.)

Summary: Better than many globals, but just barely.