Twin class

from Wikipedia, the free encyclopedia

A twin class (English twin class is) a software engineering design for the realization of multiple inheritance in the object-oriented programming .

In the case of multiple inheritance, name conflicts can occur if the same identifiers are present in the inherited base classes . This leads to a relatively high administrative effort for compilers that directly allow multiple inheritance of properties from different base classes. This problem can be avoided by using twin classes. At the same time, there is the possibility of modeling different characteristics of a property (see also diamond problem ). For example, in the case of an amphibious vehicle that inherits the properties of the land vehicle and water vehicle base classes , both of which in turn relate to the vehicle base class , the differing travel speeds on land and on water cannot easily be modeled.

In the case of twin classes, there is not just one instance that relates to two base classes, but rather a twin instance consisting of two objects in which both heirs refer to each other. An amphibious vehicle in this case would not be the same heritage of land vehicle and watercraft , but would both from an instance watercraft (with a travel speed of the water) as well as from an instance land vehicle (with a speed of travel on land). In this case, however, unchangeable properties, such as weight , may have to be managed redundantly by the programmer in both instances.

The principle of twin classes can also easily be transferred to objects with more than two base classes.

literature

  • Hanspeter Mössenböck, Object-Oriented Programming , Springer-Verlag, 1993, ISBN 3-540-55690-7