A simplified example of what i'm trying to achieve looks like this:
public class Animal
{
public virtual Teeth teeth {get;set;}
}
public class Mouse : Animal
{
public override SmallTeeth teeth {get; set;} // SmallTeeth Inherits from Teeth
}
This obviously doesn't work as teeth must be same type as in the Animal class to be overriden in the Mouse class. But can something like this be achieved where I would be allowed to use the more derived type in any functions that are inherited from Animal? For example if the Animal class contained a function to bite:
public void Bite()
{
teeth.bite()
Console.WriteLine("Ouch")
}
I could call the Bite()
function inherited from Animal and it would use the Mouse class' field of type SmallTeeth
. Is this possible? and is it the best way to do what i'm trying to do? If not, what would be the correct approach to this problem?