In most basic terms, we return to OOP 101:
Inheritance: object B "is the type of object A. The behavior and methods implemented by object A are inherited, implemented, and all (with some room for redefinition) by object B.
Interface: Object A and Object B are both examples of the "Act Like" abstract object represented by a common interface. James Gaunt uses an example if Ienumerable is higher. Other examples may be IPrintable, IDisposable, Etc.
For any given class that implements these interfaces, the implementation may be completely different (think about how you embed IDisposable in different classes that use the dispose method). However, the client code does not need to know or care about what the actual type of the object is - the code can simply access the desired properties and methods through the interface.
Inheritance is often seen as a βmagicβ response to many coding problems, but it is also widely used incorrectly as a means of avoiding redundant code. I disagree with user492238 that everything that is done with interfaces can just as easily be done through inheritance. This approach will often hit you in the corner. And, as Jodrell observes, multiple inheritance is not a .net feature (and rightfully, in my opinion).
When you find that you are implementing the same behavior in several (or many) unrelated classes, consider defining the interface that the API provides for this behavior. You can have several classes: Person, Animal, Building, etc. For each of them, you may need a method for printing. You may also have a method that takes IPrintableObject as a parameter. In this case, you can implement IPrintableObject in any of the classes that you want to print, provide implementation code in each of these objects, and pass them to the client.
source share