Alex Rivera | Logout

Should C# have multiple inheritance?

Asked 2008-10-10T14:49:58.187
54

I have come across numerous arguments against the inclusion of multiple inheritance in C#, some of which include (philosophical arguments aside):

  • Multiple inheritance is too complicated and often ambiguous
  • It is unnecessary because interfaces provide something similar
  • Composition is a good substitute where interfaces are inappropriate

I come from a C++ background and miss the power and elegance of multiple inheritance. Although it is not suited to all software designs there are situations where it is difficult to deny it's utility over interfaces, composition and similar OO techniques.

Is the exclusion of multiple inheritance saying that developers are not smart enough to use them wisely and are incapable of addressing the complexities when they arise?

I personally would welcome the introduction of multiple inheritance into C# (perhaps C##).


Addendum: I would be interested to know from the responses who comes from a single (or procedural background) versus a multiple inheritance background. I have often found that developers who have no experience with multiple inheritance will often default to the multiple-inheritance-is-unnecessary argument simply because they do not have any experience with the paradigm.

Edit
Report

4 Answers

5

YES! YES! and YES!

Seriously, I've been developing GUI libraries my entire career, and MI (Multiple Inheritance) makes this FAR easier than SI (Single Inheritance)

First I did SmartWin++ in C++ (MI heavily used) then I did Gaia Ajax and finally now Ra-Ajax and I can with extreme confident state that MI rules for some places. One of those places being GUI libraries...

And the arguments claiming that MI "is too complex" and such are mostly put there by people trying to construct language wars and happens to belong to the camp which "currently doesn't have MI"...

Just like functional programming languages (like Lisp) have been taught (by the "non-Lispers") as "too complex" by non-functional programming language advocates...

People are afraid of the unknown...

MI RULES!

answered 2008-11-25T00:38:35.887
1

While there are certainly instances where it can be useful, I have found that most of the time when I think I need it, I really don't.

answered 2008-10-10T14:56:59.110
1

I try not to use inheritance. The less I can everytime.

answered 2008-12-12T14:10:28.463
0

It would make things easier, less code, if interfaces could have implementation. But could they be miss-used more than used properly? I think that until you see how it can be done properly, you wont miss it. I get annoyed with the arguments that multiple-inheritance is unsafe. It is not. But almost all language implementations are. But do we NEED it?, I don't know.

I would prefer return type covariance, this can be added easily (just relax the rules, on the return type on over-ridden methods), and is always safe.

example:

class shape {}

class circle : shape {}

interface part {
    shape Form();
}

interface wheel : part {
    circle Form();
}
answered 2011-02-02T17:05:34.243

Your Answer