Sign in to follow this  

is it a singleton ?

Recommended Posts

aarbron    294
I've been reading about them and I happen to have a class that has no reason to be instanciated more than once (it just creates the windows and renders stuff), does that fact alone make it a "singleton" even without any kind of restricting code ?

Share this post

Link to post
Share on other sites
CTar    1134
The singleton anti-pattern isn't just about having a single instance. It consists of two parts,
1) ensuring that only one instance can be created
2) ensuring global access
If you have a single global variable, and mentions in the documentation that only a single instance should ever be created then you have a singleton. Your method of ensuring one instance is just questionable. If however you make no attempt to ensure that single instance then you won't have a singleton, just a variable.

That doesn't mean you should try to make any kind of restricting code or make your variable global. Singletons are usually a sign a of bad design and creating a single instance of a class is usually a much better solution.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this