开发者

Covariance and Contravariance with LSP

开发者 https://www.devze.com 2023-01-19 15:09 出处:网络
What is the relationship between LS开发者_运维百科P and Covariance and Contravariance? Is there any relationship? Is LSP a form of Covariance ?I wouldn\'t say that Liskov\'s Substitution Principle is

What is the relationship between LS开发者_运维百科P and Covariance and Contravariance? Is there any relationship? Is LSP a form of Covariance ?


I wouldn't say that Liskov's Substitution Principle is a "form" of covariance, so much as generic covariance allows LSP to be expressed in generic relationships. As of C# 4 / .NET 4, you can treat an IEnumerable<Banana> as an IEnumerable<Fruit> and should be able to do so without any nasty surprises - which is what LSP requires, basically.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号