开发者

Benefits of implement interface over inherit classes

what are the benefit of implementing Interf开发者_C百科ace instead of Inherit the classes in .NET? except multiple inheritance


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

  • An interface can be implemented explicitly.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜