Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Why .Net support multilevel inheretence insted of multiple inheritance?
Posted 21-Oct-12 15:33pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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. Smile | :)
 
[EDIT #2]
 
Please also see this past discussion, including my answer: Why one class cannot extend more than one class in java.[^].
 
—SA
  Permalink  
v4
Comments
Milind_T at 7-Dec-12 4:11am
   
Superb explanation!!
Sergey Alexandrovich Kryukov at 7-Dec-12 14:17pm
   
Thank you, Milind. --SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Just read about the "Diamond" Problem with multiple inheritance[^], you will get your answer.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 910
1 OriginalGriff 508
2 thatraja 225
3 Abhinav S 218
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid