I have a parent and a couple of child classes. The constructor of each child class should do nothing special, but it is still needed to pass the parameter to the parent constructor. Is there a way to reach the same thing without touching the child (without adding a constructor to each child)? I have 13 child class, which should use the same constructor as the parent. (In my case, the parent class is abstract)
public class A
{
private int _number;
public A(int number)
{
this._number = number;
}
}
and
public class B:A
{
public B(int number):base(number)
{
//Nothing here
}
...
}
Maybe I can just use the default constructor in the child class and create a static generic method in the parent class, which takes the same parameters and returns a new child:
public static T getChild<T>(int number) where T:A, new()
{
T child = new T();
T._number = number;
return child;
}
But I prefer creating object with a constructor. Is there another possibility?