Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Why .Net support multilevel inheretence insted of multiple inheritance?
Posted

The statement is inaccurate and not true. There is no such thing as "multi-level inheritance", or, if you will, every inheritance is "multi-level".

And .NET actually supports multiple inheritance, but only for interfaces. More exactly, any interface can list any number of base interfaces; and any class can list only one base class (by default, this is System.Object and any number of interfaces in its inheritance list, and should implement all of listed interfaces. This is sometimes called "weak form of multiple inheritance".

So, why not "strong" multiple inheritance, as in C++? This is pretty hard to explain. In brief, such inheritance case difficult problems in both implementation, but especially in use.
In this article, you can read about "diamond problem":
http://en.wikipedia.org/wiki/Multiple_inheritance[^].

This is not the only problem.

Unfortunately, I don't know one comprehensive article on this difficult topic; also, opinions of people are somewhat contradictory.

[EDIT #1]

Perhaps I would personally prefer to have "stronger" multiple inheritance which I would use with great care, but I would prefer finer control than that available in C++. I'm familiar with the finer multiple inheritance schema invented by one researcher I know well, but I'm afraid it is not implemented anywhere. And I don't think I know the universal solution which would be acceptable for majority of people and would somehow protect from stupid or unsafe decisions. This is a very serious problem. Having only the weak-form multiple inheritance is a kind of stay-away-of-trouble approach at the expense of insufficient expressive power. This is actually one of the most difficult and fundamental problems of OOP methodology.

[END EDIT #1]

The problem lies in the nature of things and hardly can be mitigated with one silver-bullet approach. Try to read different material on the topic: http://bit.ly/SnZLfe[^].

Besides, if you gain considerable experience in design of complex models using both single and multiple inheritance, you will be able to feel the problem on your own skin. :-)

[EDIT #2]

Please also see this past discussion, including my answer: Why one class cannot extend more than one class in java.[^].

—SA
 
Share this answer
 
v4
Comments
MT_ 7-Dec-12 4:11am    
Superb explanation!!
Sergey Alexandrovich Kryukov 7-Dec-12 14:17pm    
Thank you, Milind.
--SA
Because of Diamond problem[^] .Net doesn't support multiple inheritance.
Quote:
The biggest problem with multiple-inheritance is that it allows for ambiguity when the compiler needs to find the correct implementation of a virtual method."

As .net support Multiple Interface Inheritance.
why-doesn-t-c-support-multiple-inheritance[^]
MultipleInheritance[^]

Hope this helps :)
 
Share this answer
 
Just read about the "Diamond" Problem with multiple inheritance[^], you will get your answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900