Should I use manager classes? (Singletons)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
GreatJake
Posts: 169
Joined: January 6th, 2013, 5:13 pm
Location: USA

Should I use manager classes? (Singletons)

Post by GreatJake » July 18th, 2014, 3:32 am

Recently I read this blog thingy...
http://gameprogrammingpatterns.com/singleton.html

It basically says you should only use singletons on very rare occasions..

In the game I'm currently creating I have a bunch of singletons, for example i have a Box2DManager, CameraManager, InterfaceManager, MouseManager, KeyboardManager, MapManager, ProjectileManager, ResourceManager, TimeManager. Am i being too liberal with these singletons? Should i be passing these as parameters?

For example i can just do this.

Code: Select all

#include "MapManager"
#include "ResourceManager"

MapMgr->getMap()->addEntity(ResourceMgr->createEntity("box");
And boom instant box in my game. Whats so wrong with getting everything you want when you want it with a simple #include??

User avatar
LuisR14
Posts: 1248
Joined: May 23rd, 2013, 3:52 pm
Location: USA
Contact:

Re: Should I use manager classes? (Singletons)

Post by LuisR14 » July 18th, 2014, 11:27 am

i think it depends on the implementation of those classes (i'm not very sure), and like dam, that's some lot of managers xD
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat :mrgreen: --

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Should I use manager classes? (Singletons)

Post by chili » July 19th, 2014, 2:06 pm

Yeah, it's not really a good design paradigm. I could explain reasons why, but that article you linked does a really good job and I'd just be repeating what was said there, only not as well.


Still, I say if it works for you personally, then who cares? I think as you create more complicated systems, you'll naturally find out why globals in general aren't a good idea. And if they never are a problem for you, then more power to you. If it feels good do it. Even if you shouldn't. Don't let people mess you around.
Chili

User avatar
jkhippie
Posts: 218
Joined: March 24th, 2014, 5:11 pm

Re: Should I use manager classes? (Singletons)

Post by jkhippie » August 29th, 2014, 9:03 pm

It seems to me that globals and Singletons are a bigger problem in a team environment. If you declare a bunch - o - shit, just keep track of it and it's fine. Right? -ish?
To strive, to seek, to find, and not to yield.

Post Reply