Basically, I have:
public abstract class AbstractClass {
public AbstractClass( Type arg0, Type arg1, Type arg2 ) {
// do some stuff with all those args
}
public AbstractClass( Type onlyOneArg ) {
// do different stuffs with this different arg.
}
protected someMethods() { /* ... */ }
}
And I have a few problems in the subclasses:
- First, I have to -in most of the cases- uselessly rewrite the constructors. Not very annoying, just a bit dirty to the eye.
- And, more important, I am not forced to implement both constructors (although both are used in the program).
Example of my current subclasses:
public class MyClass extends AbstractClass {
public MyClass( Type arg0, Type arg1, Type arg2 ) {
super( arg0, arg1, arg2 );
}
public MyClass( Type onlyOneArg ) {
super( onlyOneArg );
}
}
And
- I have to be able to write some particular code in a subclass's constructor if I want.
- I have too many shared code that I want to keep in the abstract class.
Can I do something about that ? Are there something I don't know about Java ? Or is my design bad ? Or.. ?
AbstractClass's subclass, both constructors are available. In the program, I'm instantiating with both constructors without knowing the exact type. I only know that the object will be anAbstractClasssubclass. So I have to be sure that I can always use both constructors. Is that more understandable ?... Sry, hard to express my thoughts in English !AbstractClassconstructor if it is not defined in the subclass, but that is not my main concern.AbstractClass's subclass, both constructors are available" Why? What if the subclass doesn't need both constructors?