Multiple Inheritance

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m (Reverted edits by Ebybymic (Talk); changed back to last version by Matthew Harward)
 
Line 5: Line 5:
 
Multiple Inheritance is often considered a desirable feature of OO languages however, Riel claims, with relation to the introduction of MI to C++, that ''"...only 2 percent [of developers] understood why they wanted multiple inheritance and were not misusing it."''
 
Multiple Inheritance is often considered a desirable feature of OO languages however, Riel claims, with relation to the introduction of MI to C++, that ''"...only 2 percent [of developers] understood why they wanted multiple inheritance and were not misusing it."''
  
>===Acceptable Usage===
+
===Acceptable Usage===
 
Riel believes it is acceptable to use MI when the two classes that are being subclasses provide two real concepts that both provide a necessary, objective, component of the created subclass.
 
Riel believes it is acceptable to use MI when the two classes that are being subclasses provide two real concepts that both provide a necessary, objective, component of the created subclass.
  
 
[[Image:MIPenguin.png]]
 
[[Image:MIPenguin.png]]
 
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://ocefehykana.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
 
----
 
=[http://ocefehykana.co.cc CLICK HERE]=
 
----
 
</div>
 
  
 
===Unacceptable Usage===
 
===Unacceptable Usage===

Latest revision as of 03:22, 25 November 2010

Multiple Inheritance (MI) occurs when a subclass has two or more super classes.

It is an available construct in some object oriented languages including C++, Common Lisp, Curl, Dylan, Eiffel, OCaml, Perl and Python. However, it is not available in Java or C#.

Multiple Inheritance is often considered a desirable feature of OO languages however, Riel claims, with relation to the introduction of MI to C++, that "...only 2 percent [of developers] understood why they wanted multiple inheritance and were not misusing it."

Contents

Acceptable Usage

Riel believes it is acceptable to use MI when the two classes that are being subclasses provide two real concepts that both provide a necessary, objective, component of the created subclass.

MIPenguin.png

Unacceptable Usage

Riel believes that it is not acceptable to use MI when:

  • it is for the purpose of composition, e.g. an Aircraft should not inherit from Wings or a Cockpit.
  • the inheritance hierarchy is poorly defined, e.g an Orange should not inherit from Citrus and Food. It should inherit from Citrus, which should, in turn, inherit from Food.

'Mixins' and DAGs

Coming soon!

Non-MI Languages

In languages that do not support MI, several techniques can be used to provide equivalent functionality.

  • The essential superclass can still be defined.
  • Subclasses can aggregate instances of classes designed to provide the functionality of the other superclasses. In English, in order to provide the functionality lost by not using multiple inheritance, instances of classes can hold objects designed to provide the same facilities as the missing superclasses.
  • Interfaces can be used to make sure classes support specific methods and have a specific form (most OO languages can implement multiple interfaces).

See Also


Personal tools