I have a bunch of classes extending the abstract base class. Each subclass takes an array, as in the constructor (different lengths depend on the class). These classes can 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 every derived class have a static method, returning the length. However, the base class cannot provide this, since abstract static methods do not work in java. (B) Each derived class has a constructor with no arguments, and I will build such classes to be able to call the countParameters () method, which I can use from the base class. It seems "cludgy" since I am not interested in creating such an object, but it only needs information about it.
The reason is because I am creating a graphical interface that gives the user the ability to instantiate Derived classes, but each Derived class takes a different number of parameters. That is, I need to know how to draw a GUI before I can create classes.
EDIT: I could simply require that each Derived class have a private constructor, with no arguments, and using reflection, I can call the countParameters () method.
EDIT2: Actually, I'm interested in parameter names. That is, if the Derived class has a constructor
public Derived(double name1,double name2,...)
I need a way to create an array of String []
{name1,name2,...}
I think it would be impossible to do without creating an instance of the class, but in order for the user to create such a class, he needs parameter names! Moment 22.