J
Jon Skeet [C# MVP]
K Viltersten said:As a human, i'm lazy, so if i need to
write a class with three constructors,
i'd like to minimize the work. I'm used
to two different approaches and i'd
like to get an opinion on which is to
be most preferred.
// 1. Constructors calling each other.
class C {
C () {this (5);}
C (int i) {this (5, 3);}
C (int i, int j) {} }
// 2. Constructors calling a common method.
class C {
C () {common (5, 3);}
C (int i) {common (i, 3);}
C (int i, int j) {common (i, j);}
void common (int i, int j) {} }
My applogies for the ugly code. I tried to
keep it short.
I personally usually use option 1 - although I vary between a "long"
constructor chain (where the parameterless calls the single parameter,
which calls the double parameter) and "short" constructor chains (where
every constructor calls the most complicated one).