Hello all,
I am currently looking to refactor some of the code in my engine to remove some singletons I made out of laziness. However, I am facing a problem, and I am curious how others would solve this problem. As it stands, object creation within the engine is done through constructors, and internal engine dependencies are accessed through singletons. This is the main design I am trying to move away from. However, there is one distinct advantage to this approach, which I would very much like to maintain: a user needs to know very little about the internal dependencies to construct a new object, and can easily inherit from certain objects in the engine.
For example, I have in my GUI system a LabelControl class. Each LabelControl object must have access to the FontManager, which is a subsystem that allows loading, retrieving and caching of fonts (as it stands, built as a singleton). I want users of my engine to be able to construct a new LabelControl, and also inherit from LabelControl, without needing to know that the FontManager even exists. The only way I can see to solve this problem, while still keeping singletons out of my engine is to do the following:
-Take all my "singleton" subsystems and throw them into my Game base class in my engine.
- Require the user to pass their "Game" instance into every single constructor.
I'm not sure if this is the right way to do things, or if there is some other way that makes more sense. Either way, I'd love some input and opinions on the matter.
Thanks,
-Adam