Suppose we want to model different kinds of food; pizzas and pies. Both pizzas and pies do have a sort of topping, but their toppings are different.
We implement an abstract class Baked, and two concrete classes Pizza and Pie. We also implement an abstract class Topping, and two concrete classes PizzaTopping and PieTopping.
By definition, any concrete implementation of Baked must have a Topping, so Baked should have an attribute of type Topping. Also, this specific topping attribute should be of type PizzaTopping in Pizza, and PieTopping in Pie.
If I understand this previous answer correctly, the LSP is violated in this situation, because if we set aside the fact that Baked is abstract, it could be possible to instantiate a Baked holding a PieTopping, but that is not possible if we substitute Baked with Pizza.
My question is; is there a way to implement this model without violating the LSP?
Bakedsounds like it should be a boolean property of some notionalIFood, not a base type. And why must aBakedhave aTopping? A lot of baked foods don't have toppings.