Why is multiple inheritance not supported in most programming languages?

Why is multiple inheritance not supported in most programming languages?

Could I really use this feature to develop a different app layout?

+7
inheritance oop multiple-inheritance
source share
3 answers

Multiple inheritance is useful in many situations as a developer, but it significantly increases the complexity of the language, which complicates the life of both compiler developers and programmers.

  • One problem occurs when two parent classes have data members or methods with the same name. It is hard to decide what the subclass refers to.

  • The other occurs when two parent classes inherit from the same base class, forming a “diamond” pattern in the inheritance hierarchy.

  • An order that requires initialization / development of parent classes can sometimes lead to a change in behavior when the order of inheritance is changed - something may surprise developers.

  • Some languages ​​support a reference to "super" or an equivalent that refers to a base class attribute for this object. It becomes difficult to maintain in a multi-inheritance language.

  • Some languages ​​try to create an automatic object-relational model, so objects can be robust with regular RDMS. This juxtaposition is difficult in the best of times (it was described as the "war in Vietnam" of software development), but much more difficult if multiple inheritance is supported.

+9
source share

One reason for not supporting this is the ambiguity of method resolution.

http://en.wikipedia.org/wiki/Diamond_problem

However, I'm not sure what you mean by “most” programming languages. Many of those used today support it directly (C ++, Python, Perl, OCaml) or have a mechanism of similar functionality (Ruby and Scala come to mind).

+4
source share

The real reason multiple inheritance is not supported in many languages ​​is simply the laziness of the language developers. All sorts of excuses have been made to hide this embarrassing failure, “it complicates the life of the developer” bla bla, but for those who really use a language that implements it well, multiple inheritance becomes natural and easy after about 1 month, It's okay.

The only problem with this is that after you realize how useful and easy it is, you are prone to allergies to languages ​​that do not support it, and this can hold back your career prospects.

So my advice would be to stay away from him.

-4
source share

All Articles