Thursday, July 9, 2009

What are the pros/cons of multiple inheritance?

I have noticed that many more-recently developed programming languages have chosen to purposely exclude full support for multiple inheritance (as used in c++), and have not been able to find an adequate explanation of why the designers would choose to exclude this potentially very powerful feature. All I can seem to find is some very vague references to different ways that it's misuse can cause some confusion, is there more to it than that? what are the pros/cons?

What are the pros/cons of multiple inheritance?
The most cited con of multiple inheritance is that if two (or more) base classes have the same method name, which does the compiler invoke on an object of the common subclass? I think this is a valid concern. It turns programming from something enjoyable into a black art.





To be clear, this con is about multiple *implementation* inheritance, not interface inheritance. Many of the languages that have been advanced as examples of eschewing multiple inheritance (especially Java) support multiple interface, single implementation inheritance. This is safer because it allows for an obvious resolution to the question of what method will the compiler call when the method is invoked.


No comments:

Post a Comment