Multiple inheritance
From Wikipedia, the free encyclopedia
|
Multiple inheritance refers to a feature of some object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. This contrasts with single inheritance, where a class may inherit from only one superclass. Languages that mostly support multiple inheritance are: Eiffel, C++, Python, Perl, and CLOS (LISP).
Multiple inheritance allows a class to take on functionality from multiple other classes, such as allowing a class named Ambiguities arise in multiple inheritance, as in the example above, if for instance the class Musician inherited from Person and Worker and the class Worker inherited from Person. There would then be the following rules: StudentMusician: Person, Musician, Worker Musician : Person, Worker Worker: Person If a compiler is looking at the class StudentMusician it needs to know whether it should join identical features together, or whether they should be separate features. For instance, it would make sense to join the "Age" features of Person together for StudentMusician. A person's age doesn't change if you consider them a Person, a Worker, or a Musician. It would, however, make sense to separate the feature "Name" in Person and Musician if they use a different stage name than their given name. The options of joining and separating are both valid in their own context and only the programmer knows which option is correct for the class they are designing. Languages have different ways of dealing with these problems of repeated inheritance.
Java, Nemerle, C#, PHP, and Objective-C do not allow multiple inheritance; this results in no ambiguity. However, Java, Nemerle, C# , PHP version 5 and Objective-C allow classes to inherit from multiple interfaces, recreating some of the problems, for example the problem mentioned above. DebateThere is debate as to whether multiple inheritance can be implemented simply and without ambiguity. It is often criticized for increased complexity and ambiguity, as well as versioning and maintenance problems it can cause (often summarized as the diamond problem).[1] Detractors also point out multiple inheritance implementation problems such as not being able to explicitly inherit from multiple classes and the order of inheritance changing class semantics. There are languages that address all technical issues of multiple inheritance, but the main debate remains whether implementing and using multiple inheritance is easier than using single inheritance and software design patterns. See alsoReferences
External links
es:Herencia múltiple fr:Héritage multiple it:Ereditarietà multipla (informatica) pt:Herança múltipla (informática) fi:Moniperintä sv:Multipelt arv tr:Çoklu kalıtım |


