P
Paramesh
Hello friends,
My friend asked me this question:
This question regards proprietary software (of which I am one of the
developers), so I cannot post actual code for this question. I will try
to use illustrative examples.
I have two libraries for distribution; one is an essential library and
the other is an add-on (providing specialized extensions and
enhancements).
I have a factory class in the first module (lets call it Factory) which
is used to generate instances of another class (lets call it Thing).
Now, Thing itself is an abstract base class, and the first (essential)
library has some derived Things. The add-on library contains some
additional derived Things.
I am wondering whether there is a technique I can use so that the
Factory implementation (which is in the first library) has hooks to
instantiate derived Things from the add-on library, but only if the
sceond library is available. An enumeration is used to identify the
particular type of Thing to be instantiated. Even if I can control the
enumeration so that it contains only the appropriate items for the
available libraries, the user can still potentially use an invalid
value via casting, so I would still need to throw some run-time
exception if the add-on library is not available, with a message like
"feature unavailable: module x not installed".
I was thinking I might be able to do this with carefully chosen
preprocessor directives and macros, but I haven't quite figured out a
way.
Please help me with finding a solution.
Thank you,
Paramesh.
My friend asked me this question:
This question regards proprietary software (of which I am one of the
developers), so I cannot post actual code for this question. I will try
to use illustrative examples.
I have two libraries for distribution; one is an essential library and
the other is an add-on (providing specialized extensions and
enhancements).
I have a factory class in the first module (lets call it Factory) which
is used to generate instances of another class (lets call it Thing).
Now, Thing itself is an abstract base class, and the first (essential)
library has some derived Things. The add-on library contains some
additional derived Things.
I am wondering whether there is a technique I can use so that the
Factory implementation (which is in the first library) has hooks to
instantiate derived Things from the add-on library, but only if the
sceond library is available. An enumeration is used to identify the
particular type of Thing to be instantiated. Even if I can control the
enumeration so that it contains only the appropriate items for the
available libraries, the user can still potentially use an invalid
value via casting, so I would still need to throw some run-time
exception if the add-on library is not available, with a message like
"feature unavailable: module x not installed".
I was thinking I might be able to do this with carefully chosen
preprocessor directives and macros, but I haven't quite figured out a
way.
Please help me with finding a solution.
Thank you,
Paramesh.