Re: dispatch class, modularity, initialisation?
bugbear wrote:
Lew wrote:
It was not clear from your earlier posts that you were using the same
class with different parameters to configure each instance.
Not everytime, I just like the option:
The example was:
registry.add("nigel", new WidgetA());
registry.add("george", new WidgetB("arbitrary"));
registry.add("henry", new WidgetB("something"));
The same idea still works, just externalize the parameters. Jeez,
doesn't anyone extract an apply principles from fragmentary examples
any more?
Jeez - doesn't anyone read the posts they're replying to :-)
You mean like where you said,
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.
?
I provided a general pattern, handling the subclass part of your request as
being the subtler and more directly connected to the pattern. I figured the
Gentle Reader would extract what they needed from it. I showed the pattern
for sub-classes; surely you can generalize it to same class, different
parameters. (Hint: Use a factory instead of a constructor, or don't use the
default constructor but one that takes the required parameters, or use a builder.)
--
Lew