[[Property:title|Multiple inheritance]] [[Property:weight|0]] [[Property:uuid|7f54afce-fd1d-fba7-7a55-f74604ea9846]]

Multiple inheritance: definition

Multiple inheritance is a mechanism for combining abstractions. It lets you define a class by extending or specializing two or more classes, not just one as in single inheritance. For example you might define a multi_function printer as the combination of a printer and a scanner. Multiple inheritance sometimes has the reputation of being complicated or even messy, but there is no such problem in Eiffel. "Name clashes", for example, are not a big deal: if classes A and B both have a feature with the same name f and class C inherits from both, you can either specify that they should be merged, or keep them separate through the rename mechanism. Details below.

Multiple inheritance basics

Multiple inheritance happens as soon as you list more than one class in the inherit clause at the beginning of a class. For example: class PRINTER feature ... Here the features specific to printers ... end class SCANNER feature ... Here the features specific to scanners ... end class MULTI_FUNCTION_PRINTER inherit PRINTER SCANNER feature ... Here the features specific to printer-scanners ... end As with single inheritance, the new class has access to the parent features, except that here they are features of two different parents. For example if PRINTER has feature and SCANNER has features scan and scanned, then the feature clause of SCANNER can include scan_and_print -- Scan a page and print it. do scan -- Leaves result of scan in `scanned' print (scanned) end