I have a bunch of classes extending an abstract Base class. Each subclass takes an array as in the constructor, (different length depending on class). These classes could be written by other people.
What is the best way to figure out the length of the array the class needs? I could: (A) Require that each derived class have a static method, returning the length. However, the base class cannot enforce this, since abstract static methods does not work in java. (B) Each derived class have a constructor with no arguments, and I construct such classes just to be able to call the countParameters() method, that I can enforce from the Base class. This feels "cludgy", since I am not interested in creating such object, but only need some info about it.
The reason is that I am creating a GUI, that gives the user the ability to create instances of Derived classes, but each Derived class takes different number of parameters. That is, I need to know how to draw the GUI before I can create the classes.
EDIT: I could just require that each Derived class have a private constructor, with no arguments, and using reflection I can call the countParameters() method.
EDIT2: Actually, what I am interested in, is what the names of the parameters are. That is, if the class Derived have the constructor
public Derived(double name1,double name2,...)
I need a way to generate the String[] array
{name1,name2,...}
I guess this would be impossible to do without creating an instance of the class, but for the user to be able to create such class, he/she needs the parameter names! Moment 22.