Trying to practice LSP, the following is not really clear to me:
Liskov requirements (some)
-There must be contravariance of the method arguments in the subtype.
– There must be covariance of the return types in the subtype.
Also the method in a subclass could be declared with a parameter type that is more generic than in the base class, is that right? But as far as I know, that does not work, as I tried in C#:
class A
{
public virtual void Test(Cat a)
{ }
}
class B : A
{
public override void Test(Animal a) //shouldn't this work to be Liskov compliant?
{
}
}
class Animal
{ }
class Cat : Animal
{ }
As, to my knowledge, CLR does not support covariance except for delegates and generics, how can we implement truly LSP compliant code if this cannot be met?