0

what are the benefit of implementing Interface instead of Inherit the classes in .NET? except multiple inheritance

subeer haldar
  • 137
  • 2
  • 13
  • 1
    possible duplicate of [Interface or abstract class?](http://stackoverflow.com/questions/1165332/interface-or-abstract-class) – Michael Petrotta May 07 '11 at 16:23
  • I agree with Michael, this appears to be a duplicate. The OP should either refer to those answers for guidance, or should modify this question to have substantive differences. – Jason D May 07 '11 at 16:47
  • possible duplicate of [Interface vs Base class](http://stackoverflow.com/questions/56867/interface-vs-base-class) – nawfal Jul 07 '14 at 09:49

4 Answers4

5
  • A class in .NET can implement multiple interfaces, but derive only from one base class.

  • An interface can be implemented explicitly.

dtb
  • 213,145
  • 36
  • 401
  • 431
2

There is no "benefit" it's just different things. Implementing interface says "I can do something", while inhereting class says "I am something".

Petr Abdulin
  • 33,883
  • 9
  • 62
  • 96
  • 1
    That's a rather blinkered view. That's like saying that compiled languages aren't more practical than writing machine code because they are just different. A comparison becomes meaningful when you have to choose between two different things that could solve the same problem – David Heffernan May 07 '11 at 16:37
2

One key advantage of interfaces in a single inheritance language is that interfaces can be implemented on classes that do not share a common root.

Another point is that interfaces allow what is known as interface inheritance rather than implementation inheritance. This can sometimes be very useful but proponents of true multiple inheritance regard the lack of multiple implementation inheritance a crucial weakness of C#, Java etc.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
0

One can think of implementing multiple interfaces as being equivalent to inheriting from multiple pure abstract base classes. So, at some level, the conceptual difference only comes down to the fact that in implementing interfaces, you don't get an implementation for free.

Kevin Hsu
  • 1,726
  • 11
  • 14