Singletons

I decided not to hijack Stewbond's thread:
http://www.cplusplus.com/forum/general/140913/

I personally have never found much use from singletons and I generally try to avoid them in places where they are forced upon me (e.g. Bukkit).

Disch says they can be useful for resource managers, but that's no reason to actually make them a singleton, you could just have a way to access it from all parts of your program that need access, leaving you free to destruct and replace it at runtime.

So, does anyone know how singletons are even considered a design pattern? To me they just seem like demi-god objects.
Last edited on
Only real advantage I see over a global variable is ordered initialization.

I *hate* singletons. They are the most over used, overly complicated anti-pattern I have ever seen. It's a pattern people use just because others use it. Drives me bananas.
NoXzema wrote:
Only real advantage I see over a global variable is ordered initialization.
I doubt all singletons are implemented properly ;p
I thought this thread was about relation ships n stuff.
devonrevenge wrote:
I thought this thread was about relation ships n stuff.
No. On an unrelated note, it's not about relationships either.
LB wrote:
I personally have never found much use from singletons...

They have limited use in system programming from what I have read and been told.
LB wrote:
No. On an unrelated note, it's not about relationships either.

Well there is one relationship that can be formed between a Singleton and a Simpleton. The President of the United States is an example of a Singleton, but is usually populated by a Simpleton. I know, terrible joke.
I'm self taught, and IMO the terminology for describing "patterns" is my weakest point. But having read up on this concept I realize that I inadvertently have used this and that Disch is right, it's to limit the number of resources that class (it's more of a table really) consumes.

It's a very use case specific design, so I'm not sure how you can implement it where it doesn't belong. I use it in a custom object that has found it's way into a number of projects that I've written. My class uses CreateToolhelp32Snapshot to grab a snap shot of everything running on the target system and opens a handle to each process it finds. It keeps itself up to date when ever it is used so to avoid race conditions and because the list will be consistent regardless of the the child classes perspective I don't allow more then one to exist.
Topic archived. No new replies allowed.