Covariance and contravariance with LSP

What is the relationship between LSP and covariance and contravariance? Is there any relationship? Is LSP a form of covariance?

+3
source share
1 answer

I would not say that the Liskov replacement principle is a “form” of covariance, since general covariance allows LSP to be expressed in general relations. Starting with C # 4 / .NET 4, you can consider IEnumerable<Banana>how you IEnumerable<Fruit>should be able to do this without any unpleasant surprises - this is exactly what LSP requires.

+3
source

Source: https://habr.com/ru/post/1768830/


All Articles