I want to add a central data manager to my project, so that different classes can share data. It will also act as a map to avoid doubling up on resources.
I figure that there are 3 ways I can do this:
- create the manager as a global (EVIL)
- pass the manager to each class as it is created (UGLY)
- create the manager as a singleton
Every post I see says to avoid singletons, but is this a situation that breaks the rule, or is there a better solution?
Also, the graphic data above is just one type of data; realistically there will be many data types. To avoid having a whole mess of singletons, I would create a central data manager that has a factory class for each type:
Oh yeah, I'm doing this in C++, but the concepts should apply to most languages