문제

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

도움이 되었습니까?

해결책

https://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.

다른 팁

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.

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.

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#.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top