A
A. W. Dunstan
I'm developing an application where the user selects an algorithm named
in a drop-down list, optionally sets parameters, then presses "go". We
then do stuff with the results of running the algorithm, but that has
no bearing on my question.
Each algorithm is embodied in a class, where each of these classes is
derived from an abstract base class. At present, the GUI drop-down
list knows about all available algorithms at compile time, which seems
ugly.
I thought that if the base class could keep a static map of <algorithm
name, exemplar> then the GUI could iterate over the names to build the
drop-down. Hard-coding that information in the base class wouldn't be
much better than hard-coding it in the GUI, but if the map is static
and is built as the classes are loaded then I wouldn't have that
worry.
This would have worked, were it not for the fact that the GUI gets
constructed before the algorithm classes are even loaded, leaving me
with a null map. I've got a static getter method in the base class
where I can check for a null map, but until the derived classes are at
least loaded it does me no good.
Any suggestions on how to force class loading when you don't know in
advance what those classes are? I know they'll be public and derived
from my base class, but not much else.
Or is there a better way of solving this problem?
Thanks.
in a drop-down list, optionally sets parameters, then presses "go". We
then do stuff with the results of running the algorithm, but that has
no bearing on my question.
Each algorithm is embodied in a class, where each of these classes is
derived from an abstract base class. At present, the GUI drop-down
list knows about all available algorithms at compile time, which seems
ugly.
I thought that if the base class could keep a static map of <algorithm
name, exemplar> then the GUI could iterate over the names to build the
drop-down. Hard-coding that information in the base class wouldn't be
much better than hard-coding it in the GUI, but if the map is static
and is built as the classes are loaded then I wouldn't have that
worry.
This would have worked, were it not for the fact that the GUI gets
constructed before the algorithm classes are even loaded, leaving me
with a null map. I've got a static getter method in the base class
where I can check for a null map, but until the derived classes are at
least loaded it does me no good.
Any suggestions on how to force class loading when you don't know in
advance what those classes are? I know they'll be public and derived
from my base class, but not much else.
Or is there a better way of solving this problem?
Thanks.