This project is read-only.
1
Vote

Inherit constructor when there exists only one on base class

description

In absence of any clear indication of where to post such feature requests I'm repeating this one here which I submitted to the uservoice site as well.

In cases where you have some common base class which has a single non-default constructor and several classes that inherit from that base class it becomes tedious noise to repeat a essentially a non-operational constructor for each class.

Ex:
class BaseClass
{
   public BaseClass(IDependency d)
   {
      // ...
   }
}

class A : BaseClass
{
   public A(IDependency d) : base(d)
   {
      // Empty intentionally!
   }
}

class B : BaseClass
{
   public B(IDependency d) : base(d)
   {
      // Empty intentionally!
   }
}

class C : BaseClass
{
   public C(IDependency d) : base(d)
   {
      // Empty intentionally!
   }
}
The problem becomes more of an issue with the more dependencies and more instances of each inheritor.

Justification

A similar rule already exists for the default constructor which does not need to be repeated per sub-class nor does it need to be specified directly when the arguments match exactly the arguments of a constructor with a similar signature in a base class. I ask why make this a special exception for the default constructor? Why not instead extend this to all cases where there is a single constructor for a base class? Extending the existing inheritance behavior that exists for default constructors for single-constructor scenarios will still just be as unambiguous and should allow for more concise implementation in several scenarios. Additionally this should not cause any backwards compatibility problems in that it would only allow omitting code that was once required.

comments