this question has answer here:
- a use multiple inheritance? 12 answers
can provide real-world examples when problem can more addressed using multiple inheritance rather using composition or other alternatives?
when should 1 use multiple inheritance?
why languages support multiple inheritance (c++, python) , others don't (java, ruby)? mean - based on factors creators of programming languages decide include support mi or not.
multiple inheritance used integration purposes, i.e. when need object implements required functionality of classes derives from. whether amounts "better" solution possible alternatives, matter of debate or taste, you're lucky question wasn't closed opinion-based.
with regard examples,
- this article on using python's super() multiple inheritance shows example of implementation sharing. can't have interfaces or composition,
- a similar example explained on wikipedia page on multiple inheritance deriving
buttonrectangle,clickable(it has long list of languages supporting mi), - an answer previous question for mi examples points
observable, like, @ least bertrand meyer claims cleaner implemented mi without (hence you're lucky question didn't closed duplicate).
from personal experience, multiple inheritance can quite helpful, can big problem easily. wikipedia page discusses diamond problem extent: boils down question should happen if 2 or more base classes provide implementation of method. languages need define / implement way deal this, typically defining method resolution order (e.g. python's mro).
the conflict potential increases, of course, number of base classes , number of methods. had case once framework (implemented in python) using employed multiple inheritance of handful of base classes class had derived from. happily override inherited method without being aware of it.
multiple inheritance, while useful, can seen violation of single responsibility principle: definition, class deriving multiple base classes behave either class. it's hence quite data modelling perspective, liskov substitution principle violated.
so, believe creators of programming languages might recognize multiple inheritance seen not free of conceptual issues , might require substantial implementation effort while providing limited added value on other solutions -- that's personal guess.
Comments
Post a Comment