I have a class (for argument sake, say a logging class, or a language file, etc.) that is instantiated by a calling program and then passed into a static library as a part of the initialization.
How do I define the starting DLL class to accept the passed in class and make it usable by all objects throughout the DLL. Some of the ways I have considered are:
- Static object
- Singleton
- Direct Injection
But there seem to be issues with all of these:
Static and Singleton have their issues, especially in VS2013 which doesn't always play nicely during construction/destruction.
Direct Injection would be ok, but because a large majority of these classes are available externally, it would change the whole paradigm of the API from an approach of direct instantiation of objects to one that requests objects to be created. i.e.
Instead of writing:
Country c;
State s;
c.states.push_back(s);
To something more like:
Country c;
auto state = c.addState();
Can someone point me to a proper pattern for how this is done within a DLL?
Am I forced into a singleton class?
Aucun commentaire:
Enregistrer un commentaire