Are you sure DEF
needs to extend ABC
- I mean, is a DEF
logically a ABC
? Inheritance is powerful but needs to be used with caution.
In your case, I'd rather have:
public interface WithVariable {
int[] getVariable();
}
And have both ABC
and DEF
implementing WithVariable
. This way constructing a ABC
object will initialise the needed variable, and constructing a DEF
object won't do anything, but they'll both reply to the same message (getVariable()
).