Re: Constructor call constructor



Geoffrey wrote:
Personnaly, I choose to place all the code in the constructor with all the parameters.

The constructors with minder parameters are only "shortcuts" for the full constructor

I agree. I have tried both ways and I find it much clearer putting all
of the code in the constructor with the most parameters and then
setting up the other constructors as "shortcuts" to it.

The only problem comes when you introduce inheritance where the child
class also has the same "shortcut" scheme. It's a toss-up as to whether
the child class should do the same as the parent, duplicating the
default values for the optional arguments, or call the parent's
"shortcut" constructors, thus duplicating the code that initializes
fields in the child.

I still haven't figured out a clean way to handle that one. Any takers?

.



Relevant Pages