Imagine a base class with many constructors and a virtual method
public class Foo
{
...
public Foo() {...}
public Foo(int i) {...}
...
public virtual void SomethingElse() {...}
...
}
and now i want to create a descendant class that overrides the virtual method:
public class Bar : Foo
{
public override void SomethingElse() {...}
}
And another descendant that does some more stuff:
public class Bah : Bar
{
public void DoMoreStuff() {...}
}
Do i really have to copy all constructors from Foo into Bar and Bah? And then if i change a constructor signature in Foo, do i have to update it in Bar and Bah?
Is there no way to inherit constructors? Is there no way to encourage code reuse?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…