why multiple class inheritance is not supported in C# .NET
-
Hi all can someone pls tell me why multiple class inheritance is not supported in C#.net? thanks
From WikiPedia[^]: Multiple inheritance can cause some confusing situations (I believe they're referring to the diamond problem - see this[^] link. -- Ravi), so there is some debate over whether or not its benefits outweigh its risks. Java compromises: it allows a class to inherit interfaces from more than one parent (that is, one can specify that a class inherits all the types from its parents and must have all of the same externally exposed methods of its interface-parents, and allow the compiler to enforce that), but can inherit implementation (methods and fields) from only one parent. Microsoft's .NET languages such as C# and Visual Basic implement this interface approach as well. In contrast C++ implements full multiple inheritance. /ravi
My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com
-
Hi all can someone pls tell me why multiple class inheritance is not supported in C#.net? thanks
One reason why it is not supported is that .NET was designed to be multi-language and most OO languages don't support MI. However, Eiffel .NET does (I think uniquely) support MI on .NET in a very ingenious way. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/pdc_eiffel.asp[^]
Kevin
-
Hi all can someone pls tell me why multiple class inheritance is not supported in C#.net? thanks
I asked a C# instructor several years ago this question. He said it was because the designers were worried the dumb people wouldn't understand multiple inheritance. (He added that most the dumb things in C# were done for this reason.) This response is flippant, but I suspect more true than not. Multiple inheritance is very powerful and rarely used in good code, but when needed, it's really needed. The solution was interfaces. Personally, I'd rather have had multiple inheritance, but what can you do? (I also think they should have had a scoped destructor mechanism built in. I'm sure everyone has their list of complaints.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke