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.
加载中,请稍侯......
精彩评论