You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use an abstract interface the compiler can check at compile time if the handed class instance implements all of the methods, events and properties of it. You can then pass any class that fits.
publicclassCat{voidWalk();intLegs{get;set;}voidJump();}publicvoidGo(IAnimalanimal){
animal.Walk();}publicstaticvoidMain(){varmyCat=new Cat();
Go(myCat);// compiler checks if myCat fulfills the IAnimal abstract contract}
In case of a cat that has paws instead of legs I think it would be better to stick with the current standard and define a derived class with an corresponding copy constructor
During discussing #9132 I had the idea to propose
abstract interface
When you use an abstract interface the compiler can check at compile time if the handed class instance implements all of the methods, events and properties of it. You can then pass any class that fits.
In case of a cat that has paws instead of legs I think it would be better to stick with the current standard and define a derived class with an corresponding copy constructor
It should not be possible to 'derive' from an abstract interface, like with an abstract class definition, just to stay consistent.
The text was updated successfully, but these errors were encountered: