What's a more elegant way of having the code below where i want to return a derived class based on the type of another class.
if (option_ is Rectangle)
{
modelInputs = new Foo();
}
else if (option_ is Circle)
{
modelInputs = new Bar();
}
else if (option_ is Triangle)
{
modelInputs = new Bar2();
}
Have Rectangle, Circle and Triangle implement IHasModelInput:
interface IHasModelInput
{
IModelInput GetModelInput();
}
then you can do
IModelInput modelInputs = option_.GetModelInput();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With