Page 3 of 3

Re: Is this a good programming practice

Posted: Fri Dec 05, 2008 8:52 am
by avansc
Singletons are not inherently globally available/changeable(at least no more than any other local variable)
SINGLETONS is just a desing pattern, you could store it globally, but that does not mean singletons are bad, just the programmer.

a physics engine in a game is a singleton design, you cant change the physics from the NPC class (unless you THE PROGRAMMER provide that functionality).

Re: Is this a good programming practice

Posted: Sun Dec 07, 2008 9:33 pm
by bugmenot
The general argument against Singletons is that there isn't any real reason to have restriction the 'can only create one instance' by design because in theory there are very few scenarios where it must be enforced by design. For example, you may have more then one physics world instance if you have an odd multi-player mode. If you used a legacy framework or library which had the physics world class as a singleton, it would mean that you have to to some refractoring of that class any any others that relied on this fact whereas it could have originally been simply a local instance of the class without the design restriction of a singleton.

Offtopic: I be weary of using malloc to allocate memory for a class as it doesn't call the class's constructor whereas new does.