I currently have the following code pattern, where I am initialising a particular object of type MyThing in the constructor of the general class MyClass. However, in some specific derived class examples (e.g. MySpecialClass), I want to use a derived version of MyThing, which I have called MySpecialThing.
public class MyClass
{
public MyClass()
{
this.MyThing = new MyThing();
}
public MyThing MyThing { get; set; }
}
public class MySpecialClass : MyClass
{
public MySpecialClass()
{
this.MyThing = new MySpecialThing();
}
}
My question is whether this is bad practice because in effect the MyThing property is being initialised twice, once in the base class and once in the derived class. Obviously I could pass in a boolean to the base class constructor or something to tell it not to bother initialising MyThing, but that might be overkill...