Multiple inheritance

from Wikipedia, the free encyclopedia
UML class diagram of multiple inheritance

In the object-oriented programming is multiple inheritance if a class derived directly from more than one base class inherits. A sequential, multi-level inheritance, however, is not referred to as multiple inheritance.

An example of this is the modeling of an amphibious vehicle that inherits the attributes of both land vehicles and water vehicles. This means that the amphibious vehicle has both a number of wheels and a draft .

Only a few programming languages ​​offer the possibility of multiple class inheritance, for example C ++ , CLOS , Eiffel , Perl and Python . A common objection to multiple class inheritance is that it can make design unnecessarily complicated and obscure. This can lead to ambiguities in the context of the diamond problem . In some programming languages, such as Oberon and its further developments, the option of multiple implementation inheritance was therefore deliberately omitted, which can be compensated for by using twin classes.

In contrast, multiple interface inheritance is not a problem. In Java , Object Pascal (Delphi), C # and VB.NET , a class can inherit any number of interfaces . With this, this class undertakes to make the methods of the interface available and thus also creates something similar to the is-a- relationship, the relationship -like- relationship.

With simple class inheritance and multiple interface inheritance, most of the requirements for software design can be met without having to accept the disadvantages of unrestricted multiple inheritance.

literature

  • Bernhard Lahres, Gregor Rayman: Practical book object orientation. From the basics to implementation . Galileo Press, Bonn 2006, ISBN 3-89842-624-6
  • Iain D. Craig: Object-Oriented Programming Languages: Interpretation . Springer Verlag, London 2007, ISBN 1-84628-773-1

Individual evidence

  1. Hanspeter Mössenböck: Object-oriented programming in Oberon-2. Springer-Verlag, 1993.

Web links