Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Even if it could be bad practices, I would say that there is time that it would fulfill its purpose.

share|improve this question
1  
I just love how everybody makes all these excuses for the absence of a totally useful capability in whatever Microsoft produces (MVPs are especially adept at this). My guess is that most of the folk who don't understand the benefits of multiple inheritance are the ones who don't understand (and don't use) inheritance in the first place, because they prefer the ever-popular copy-and-paste-the-code-20-times that I see in almost every project everywhere. No doubt if and when Microsoft decides to implement MI, everyone will suddenly become a wizened enthusiast, no wait an "evangelist", claiming to –  user52423 Apr 20 '12 at 15:42
1  
@DaveZiffer probably, but it appears to be hard to get right. Do you know of a language or implementation where it works really well? –  user1249 Apr 20 '12 at 16:10
4  
@Dave Or you just overestimate its usefulness. Inheritance in general is way overrated, and the missing cases can be easily modelled using interfaces and composition. Multiple inheritance really is useless in C#. The only advantage that is has is that it obviates the need to manually delegate the interface methods to the implementation in the composite members. This could have been solved better (e.g. by introducing mixins) but it’s no good reason to introduce multiple inheritance. –  Konrad Rudolph Apr 20 '12 at 16:14
    
I've been coding OO in java for many years now making reasonable use of inheritence (Heavily at times, less when I learned better) and I have found exactly 1 time when it was really hard to get around multiple-inheritence and maybe 10 times where I could have used it to simplify my current design--and exactly zero times when I couldn't redisign it not to need multiple inheritence and have the overall design better than it would have been with it. –  Bill K Jul 20 '12 at 15:59
add comment

5 Answers

up vote 12 down vote accepted

http://stackoverflow.com/questions/995255/why-is-multiple-inheritance-not-allowed-in-java-or-c covers this question nicely.

My take on it is this: The designers probably wanted to make a language that promoted good design principles. Ok, so there are times that multiple inheritance is perfect. Those are the exception, rather than the rule, though, and can be abused very easily. So, the designers decided to make it impossible to do.

For those cases where it would be good, you need to use interfaces. Those work, albeit clumsily; but, you won't need them for that that much.

share|improve this answer
add comment

Because the language designers apparently wanted to produce a better C++, not a better language in general. (How successful they were can be debated.)

C++-style multiple inheritance has some problems, and so people deriving from C++ generally omitted it (Java, C#, D). Other languages, Eiffel and Common Lisp to name two, do it differently and don't seem to have the same problems.

share|improve this answer
add comment

Walter Bright is both the creator of D, which does not include MI, and the only person ever to write an entire C++ compiler by himself. According to him, the reason D lacks MI is that it's too hard to create a system of MI that's simultaneously efficient, simple and useful. I suspect Java and C# use similar reasoning. Languages like Perl and Python don't have efficiency as a primary goal, so they have a system that's simple and useful, but hard to implement efficiently. C++ doesn't seem to have simplicity as a goal, so it created a massively complicated system that almost noone understands.

I think Walter is right on target. If there exists any language that has an MI system that satisfies all three of these criteria reasonably well, please leave a comment.

share|improve this answer
1  
What do you think about Eiffel, Common Lisp and Dylan? I know that all three of them are both simple and useful. And I know that both Common Lisp and Dylan can compete with and even beat C++ (and often even C) in performance, so that seems to satisfy efficiency. I do know that the Eiffel compiler is horribly slow but I know next to nothing about the performance of the compiled code it produces. –  Jörg W Mittag Nov 10 '10 at 10:00
add comment

Multiple inheritance, if you use it a lot, results in very complex situations. Too much complexity with little benefit is why it was ruled out for both Java and C#.

share|improve this answer
add comment

Just to illustrate why not, multiple inheritance is supported by C++, but is strongly discouraged as you can accomplish most of the stuff with composition that you would with M.I., however in a much cleaner fashion. Unlike C++, C# is not a "hybrid" type OOP language, i.e. it didn't evolve from a previous language.

If you really need multiple inheritance, you can implement multiple interfaces.

share|improve this answer
    
+1 "Favor compisition over inheritance" –  marco-fiset Apr 20 '12 at 17:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.