i saw often people use this code like
interface IAnimal
{
void die();
}
class Cat : IAnimal
{
void die() { ... }
void meow() { ... }
}
IAnimal anAnimal = new Cat();
Cat aCat= new Cat();
C# knows for sure anAnimal.die() works, because die() is defined in IAnimal. But it won't let you do anAnimal.meow() even though it's a Cat, whereas aCat can invoke both methods.
so tell me why & when we should write this kind of code
IAnimal anAnimal = new Cat();
what is the advantage ??
thanks