Let's say I have an abstract base class, Shape and then three derived classes: Triangle, Rectangle and Pentagon. The derived classes must be created based on a requirement so I could have several of each of the derived classes. The base class has quite a few fields and I was looking for a way to set the base class properties only once and then just set the different fields for the derived classes later. Since you cannot instantiate an abstract class, what is the best way to do this? I was thinking maybe create another class that derives from Shape that only has the properties of Shape, set those properties and then cast it but this seems inefficient and has code smell written all over it. Can someone suggest a better way? Thanks. Below I have written some pseudo code for the situation
public abstract class Shape
{
public int x, y, z;
}
public class Triangle : Shape
{
public int a, b, c
}
public class Facade : Shape
{
}
private Facade InitializeBaseProperties()
{
Facade f = new Training
{
x = 1, y = 2, z = 3
};
return f;
}
private void someMethod()
{
var tmp = InitializeBaseProperties();
Triangle triangle = tmp;
}