- authors: Robert Cartwright
- year: 2013
- url: https://www.cs.rice.edu/CS/PLT/Publications/Java/Inheritance.pdf
- abstract: Since Luca Cardelli wrote a seminal paper [3] on the semantics of inheritance in 1984, programming language researchers have constructed a variety of structural models of object-oriented programming (OOP) founded on Cardelli’s work. Since Cardelli approached OOP from the perspective of functional programming, he identified inheritance with record subtyping—an elegant choice in this context. Although Cardelli did not formally define inheritance, he equated it with record extension and proved that for a small functional language with records, variants, and function types–but no recursive record types–that syntactic and semantic record subtyping were equivalent. William Cook et al [4] subsequently added ThisType and recursive record types, narrowing the typing of this in inherited methods, and reached a profoundly different conclusion: inheritance is not subtyping. Meanwhile, object-oriented (OO) program design emerged as an active area of research within software engineering, spawning class-based OO languages like C++, Java, and C#, which strictly define inheritance in terms of class hierarchies. In these languages, subtyping is identified with inheritance. In contrast to Cardelli’s expansive formulation of inheritance based solely on record interfaces (sets of member-name interface pairs), these languages define the type associated with a class C as the set of all instances of C and all instances of explicitly declared subclasses of C. Simply matching the signatures of the members of C–as in record subtyping–is insufficient. It is easy to show that record subtyping is too weak to capture the notion of inheritance in nominally typed OO languages. Consider classes Set and MultiSet intended to represent mathematical sets and multi-sets respectively. They can easily have exactly the same visible members with exactly the same types. Assume that Set and MultiSet are defined independently but have exactly the same visible members. If objects simply denote records, then each class is a subtype of the other, but in a nominal OO language, no such subtyping relationship exists between the two classes. In nominal OO languages, objects are more than mere records.