开发者

Covariance and Contravariance with LSP

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜