Peter said:
I would make the string the name of a shared library or dll.
And please pass a const char * or even better a const std::string &.
This DLL should export a well-known function by name.
This well known function can be a function to create a factory class
instance
or maybe the finally class directly.
This way you can introduce new functionality which is not known at
compile time.
I was playing with a similar idea for some generic I/F handler.
There was actually no requirement by customer for this and i didn't find
"spare time" to exercise.
But my approach would have been to do it the other way around:
Let the libraries (which implement the types of objects, that are to be
created by the factory) themselves invoke some (static?) register()
function of the (one!) factory to make them be known by the factory.
I.e. the factory doesn't need to know in advance, which kind of
polymorphic objects it handles. It just needs to know the subset of
their interface needed to construct them. BTW: for the "things" to
contruct, you then "naturally" would already have defined an abstract
base class. And actually this base type is the only type of object the
factory need to return for its make().
Also the "string" that identifies the type of objects could be
registered by the various object types themselves:
static bool(?) factory::register(std::string const& myId)
factory could use a std::map<std::string> to save a list of registered
objects.
And so it could delegate its make() to the make() of the types themselves.
The main module (configuration setup) could just have a configuration
file, that list the libs to load dynamically.
I am pretty sure it will work
(at least on unix).
\Frank