Why C# (and .NET) does not support multiple-class-inheritance?
-
I am myself not a great admirer of this feature and I understand we can still do the needful using interfaces. But I am interested in *technical reasons* why .NET guys decided to omit this feature from .NET :confused: This seems to be a favourite interview question.
-
I am myself not a great admirer of this feature and I understand we can still do the needful using interfaces. But I am interested in *technical reasons* why .NET guys decided to omit this feature from .NET :confused: This seems to be a favourite interview question.
Here is a little things that I read recently. C# offers only single inheritance which means that a class can have only one direct base class. This restriction is actually imposed by the CLR so single inheritance is the rule for all .NET languages. The designers of .NET acknowledge that multiple inheritance is more powerful than single inheritance; however, they decided that the extra complications and ambiguous situations that arise in the presence of multiple base classes were not worth this extra power. Steve Maier, MCSD MCAD
-
Here is a little things that I read recently. C# offers only single inheritance which means that a class can have only one direct base class. This restriction is actually imposed by the CLR so single inheritance is the rule for all .NET languages. The designers of .NET acknowledge that multiple inheritance is more powerful than single inheritance; however, they decided that the extra complications and ambiguous situations that arise in the presence of multiple base classes were not worth this extra power. Steve Maier, MCSD MCAD
Hey thanks buddy, that’s right. :rose: I think, I should frame my interview answer as follows: (1) As one of the core features, .NET platform targets to support multiple languages. The internal constructs of each language compiler to implement MI differ. (2) The cost of implementing MI (especially due to above mentioned reason) is quite high as MI is relatively rarely used in most OOP designs. For those rare situations, interface based MI, which does not involve much of an overhead and complexities, can be used. (3) A language or platform supporting MI becomes rather complex from developer as well as the compiler writer perspective because of the confusion involved in casting, member references ambiguity, serializing and so on. .NET aims to be a clean and intuitive platform. Howz that? ;)
-
Hey thanks buddy, that’s right. :rose: I think, I should frame my interview answer as follows: (1) As one of the core features, .NET platform targets to support multiple languages. The internal constructs of each language compiler to implement MI differ. (2) The cost of implementing MI (especially due to above mentioned reason) is quite high as MI is relatively rarely used in most OOP designs. For those rare situations, interface based MI, which does not involve much of an overhead and complexities, can be used. (3) A language or platform supporting MI becomes rather complex from developer as well as the compiler writer perspective because of the confusion involved in casting, member references ambiguity, serializing and so on. .NET aims to be a clean and intuitive platform. Howz that? ;)
Sounds pretty good. On my last .Net related interview I did not need to answer questions like that. There were some technical questions, but it was mainly system based, like how do you handle this situation on a web server farm. Steve Maier, MCSD MCAD
-
Sounds pretty good. On my last .Net related interview I did not need to answer questions like that. There were some technical questions, but it was mainly system based, like how do you handle this situation on a web server farm. Steve Maier, MCSD MCAD
Oh yeah, oh yeah... Exactly! I would love to hear some real-world stuff like that from those guys. Salil Khedkar [^]