PS: how is this SFML related???or graphics related!
and since cannon needs singletonRight there I died a little inside :(
Is it just as bad when you declare a class normally and fill it with variables that need to be passed to a group of functions, then just define a single instance of that class, rather than specifically restricting it to one, and it is created in main? Is there a problem with that?That's the way you usually do it -- why should it be bad?
Thank you, it's just that when I was first using OOP, the first way it occurred to me to do things is as above and then I heard about singletons being a bad idea and this sounded to me like any class which is designed so that it only makes sense to have one instance is a bad thing, for example I almost always have a brain class that holds all of the fundamental variables and handles background functions and I've always had a nagging doubt that the don't use singletons advice could apply to that sort of thing, even though it's just a normal class (or struct) first instanciated at the start of main().Is it just as bad when you declare a class normally and fill it with variables that need to be passed to a group of functions, then just define a single instance of that class, rather than specifically restricting it to one, and it is created in main? Is there a problem with that?That's the way you usually do it -- why should it be bad?
Except that in bigger projects, you probably won't use main() for that...
[...] and this sounded to me like any class which is designed so that it only makes sense to have one instance is a bad thingThere are many classes of which there exists only one instance at a time, simply because of the nature of the concept they represent: application, game, world, camera...
for example I almost always have a brain class that holds all of the fundamental variables and handles background functions and I've always had a nagging doubt that the don't use singletons advice could apply to that sort of thing, even though it's just a normal class (or struct) first instanciated at the start of main().Depending on what your brain class does, it may be built upon a different anti-pattern: god class (too many responsibilities). Your failure to describe it concretely ("fundamental variables and background functions") is a strong indicator for that :P
Jesper: tough battle eh? 8)Yeah. I doubt we'll ever win the war. But we may win a few battles and that still has some value I guess...
Singletons are fine. Just use a proper singleton class, and understand how and when to use them.I guess we'll just have to agree to disagree.
Isn't that more-or-less what I already said as the first reply in this thread? ;)