B
bugbear
I would like to have a base class
"Widget", that amongst other things
has a method getWidgetFor(String name).
I would like this method to be able to use (e.g.)
a Widget class static HashMap to look up Widgets.
Each entry in the Map will be an instance
of a sub-class of widget; some sub-classes
may "want" to put more than one entry in the map.
So - how do I populate the map?
If I have a static block in each sub-class,
I have no trivial way of ensuring
that ALL my subclasses have been referred
to (thus loading them, and running any static
code blocks).
If I have an "init()" method in each sub-class,
it might be called more than once.
I welcome advice, tip, examples, opinions etc.
BugBear
"Widget", that amongst other things
has a method getWidgetFor(String name).
I would like this method to be able to use (e.g.)
a Widget class static HashMap to look up Widgets.
Each entry in the Map will be an instance
of a sub-class of widget; some sub-classes
may "want" to put more than one entry in the map.
So - how do I populate the map?
If I have a static block in each sub-class,
I have no trivial way of ensuring
that ALL my subclasses have been referred
to (thus loading them, and running any static
code blocks).
If I have an "init()" method in each sub-class,
it might be called more than once.
I welcome advice, tip, examples, opinions etc.
BugBear