Abstract
© Yanlin Wang, Haoyuan Zhang, Bruno C. d. S. Oliveira, and Marco Servetto. Multiple inheritance is a valuable feature for Object-Oriented Programming. However, it is also tricky to get right, as illustrated by the extensive literature on the topic. A key issue is the ambiguity arising from inheriting multiple parents, which can have conflicting methods. Numerous existing work provides solutions for conflicts which arise from diamond inheritance: i.e. conflicts that arise from implementations sharing a common ancestor. However, most mechanisms are inadequate to deal with unintentional method conflicts: conflicts which arise from two unrelated methods that happen to share the same name and signature. This paper presents a new model called Featherweight Hierarchical Java (FHJ) that deals with unintentional method conflicts. In our new model, which is partly inspired by C++, conflicting methods arising from unrelated methods can coexist in the same class, and hierarchical dispatching supports unambiguous lookups in the presence of such conflicting methods. To avoid ambiguity, hierarchical information is employed in method dispatching, which uses a combination of static and dynamic type information to choose the implementation of a method at run-time. Furthermore, unlike all existing inheritance models, our model supports hierarchical method overriding: that is, methods can be independently overridden along the multiple inheritance hierarchy. We give illustrative examples of our language and features and formalize FHJ as a minimal Featherweight-Java style calculus.
Highlights
Inheritance in Object-Oriented Programming (OOP) offers a mechanism for code reuse
This paper presents a new model called Featherweight Hierarchical Java (FHJ) that deals with unintentional method conflicts
Many OOP languages are restricted to single inheritance, which is less expressive and flexible than multiple inheritance
Summary
Inheritance in Object-Oriented Programming (OOP) offers a mechanism for code reuse. many OOP languages are restricted to single inheritance, which is less expressive and flexible than multiple inheritance. Inheritance allows one feature to be inherited from multiple parent classes that share a common ancestor. When there are multiple branches that cause unintentional conflicts, the static type can specify one branch among them for unambiguity, and the dynamic type helps to find the most specific implementation In that case, both unambiguity and extensibility are preserved. It allows overriding to work for classes with multiple (conflicting) methods sharing the same names and signatures. Note that hierarchical overriding is denoted in the UML diagram with the notation draw()↑Drawable, expressing that the draw method from Drawable is overridden In this example only one of the draw methods is overridden (and the other is inherited), hierarchical overriding supports multiple conflicting methods to be independently overridden as well. The implementation can type-check and run variants of all the examples shown in this paper
Talk to us
Join us for a 30 min session where you can share your feedback and ask us any queries you have