I derive a bunch of models from a base model class. Here is an example of one such child model:
namespace MyProject.Models
{
public abstract class Parent1 {}
}
namespace MyProject.Models
{
public class Child1: Parent1 { ... }
}
Each of these models has pretty consistent functionality, which I code in separate classes I call "handlers." There is a base handler, to define the method names:
namespace MyProject.Models
{
public abstract class Parent1Handler
{
public abstract void Update(Parent1 model);
}
}
But when I try to create a derived handler, .NET is unhappy with my parameter type:
namespace MyProject.Models
{
public class Child1Handler: Parent1Handler
{
public override void Update(Child1 model) { ... }
}
}
It essentially demands that I use an argument of type Parent1 to override my method. But Child1 is derived from Parent1; shouldn't an argument of type Child1 be a suitable stand-in?
Update(Parent1 model)andUpdate(Child1 model)-> should the overriden method override the 1st or 2nd? Among others, that is the reason why it must be exactly same.