P
Paul Chapman
I'm a Java novice, but an experienced Smalltalk and C++ programmer.
I have this fairly large class heirarchy, with all but the leaves abstract.
One of the base class's fields is to be initialized with a value provided to
a static factory method which selects the right subclass, *except* in one
leaf case where it is replaced with something else.
I find I have to have a constructor in every class which simply calls super
with the same argument all the way up to the top.
It would frankly be a lot less code to have a separate setField() method to
set that field, which is defined in the base class and overridden in that
one case.
I am torn between doing it the "right" way, with all those extra and quite
pontless super-calling constructors, and the "wrong" way which cuts them
out.
I'm someone who generally believes (up to a point) that *short* code is more
easily understood and maintained than *long* code. Should I carry this
belief into Java in this instance?
Cheers, Paul
I have this fairly large class heirarchy, with all but the leaves abstract.
One of the base class's fields is to be initialized with a value provided to
a static factory method which selects the right subclass, *except* in one
leaf case where it is replaced with something else.
I find I have to have a constructor in every class which simply calls super
with the same argument all the way up to the top.
It would frankly be a lot less code to have a separate setField() method to
set that field, which is defined in the base class and overridden in that
one case.
I am torn between doing it the "right" way, with all those extra and quite
pontless super-calling constructors, and the "wrong" way which cuts them
out.
I'm someone who generally believes (up to a point) that *short* code is more
easily understood and maintained than *long* code. Should I carry this
belief into Java in this instance?
Cheers, Paul