Polymorphism AND type safety in parallel inheritance chains
问题 I have two parallel inheritance chains: Chain1: Animal <- Lion <- Gazelle Chain2: Food <- Meat <- Grass I want to implement the "Eats" polymorphic property on Animal. This is how it looks like: public abstract class Animal { public abstract Food Eats { get; set;} } public class Lion : Animal { public override Food Eats { get { return new Meat();} set { if (value is Meat) DoSomething(value); else throw new Exception("Lions only eat meat. " + "You better learn that, dude!"); } } } However, this