On the Notion of Inheritance [Pdf]

On the Notion of Inheritance [Pdf]

On the Notion of Inheritance ANTERO TAIVALSAARI Nokia Research Center One of the most intriguing—and at the same time most problematic—notions in object-oriented programming is inheritance. Inheritance is commonly regarded as the feature that distinguishes object-oriented programming from other modern programming paradigms, but researchers rarely agree on its meaning and usage. Yet inheritance is often hailed as a solution to many problems hampering software development, and many of the alleged benefits of object-oriented programming, such as improved conceptual modeling and reusability, are largely credited to it. This article aims at a comprehensive understanding of inheritance, examining its usage, surveying its varieties, and presenting a simple taxonomy of mechanisms that can be seen as underlying different inheritance models. Categories and Subject Descriptors: D.1.5. [Programming Techniques]: Object- Oriented Programming; D.3.2. [Programming Languages]: Language Classifications object-oriented languages; D.3.3. [Programming Languages]: Language Constructs and Features General Terms: Languages Additional Key Words and Phrases: Delegation, incremental modification, inheritance, language constructs, object-oriented programming, programming languages 1. INTRODUCTION only currently well-developed and widely accepted area seems to be the A characteristic feature of object-ori- theory of inheritance in terms of denota- ented programming is inheritance. In- tional semantics [Cook 1989a; Cook and heritance is often regarded as the fea- Palsberg 1989; Reddy 1988]. ture that distinguishes object-oriented Despite the fact that much effort has programming from other modern pro- been targeted on research into inheri- gramming paradigms, and many of the tance in the past years, it seems that alleged benefits of object-oriented pro- inheritance is still often inadequately gramming, such as improved conceptual understood. Many studies of inheritance modeling and reusability, are largely concentrate only on one specific view- accredited to it. Despite its central role point, such as type theory or conceptual in current object-oriented systems, in- modeling, and mostly ignore the other heritance is still quite a controversial possible viewpoints. Depending on the mechanism, and researchers tend to dis- viewpoint, inheritance is regarded ei- agree on its meaning and usage. The ther as a structuring or modeling mech- Author’s address: Nokia Research Center, P.O. Box 45, 00211 Helsinki; Finland; email: antero. [email protected]. Permission to make digital/hard copy of part or all of this work for personal or classroom use is granted without fee provided that the copies are not made or distributed for profit or commercial advantage, the copyright notice, the title of the publication, and its date appear, and notice is given that copying is by permission of the ACM, Inc. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and/or a fee. © 1996 ACM 0360-0300/96/0900–0438 $03.50 ACM Computing Surveys, Vol. 28, No. 3, September 1996 On the Notion of Inheritance • 439 anism for reasoning about programs, or currently used synonyms for inheri- a mechanism for code sharing and re- tance in object-oriented systems are use. It seems that a more general, com- subclassing, derivation (in C11) and prehensive view of inheritance is still prefixing (in Simula and Beta); in some missing. The main motivation for this papers the term subtyping is also used article was the desire to reach a more in the same meaning [Halbert and thorough understanding of inheritance O’Brien 1987], although more commonly from different viewpoints. that term is reserved for another pur- This article provides a comprehensive pose, as will be discussed in Section introduction to inheritance, starting 2.2.2. from its history and conceptual back- The basic idea of inheritance is sim- ground, examining its intended and ac- ple. Inheritance allows new object defi- tual usage, and discussing its essence in nitions to be based upon existing ones; light of the current knowledge. Further- when a new kind of an object class is to more, the varieties of inheritance are be defined, only those properties that analyzed, and a simple taxonomy of in- differ from the properties of the speci- heritance mechanisms is presented. fied existing classes need to be declared This article is a continuation to an ear- explicitly, while the other properties are lier article on object-oriented program- automatically extracted from the exist- ming [Taivalsaari 1993a], and part of a ing classes and included in the new larger study of inheritance, published class. Thus, inheritance is a facility for as the author’s doctoral thesis [Taival- differential,orincremental program de- saari 1993c]. velopment. Formally, inheritance can be characterized as follows [Bracha and 2. INHERITANCE Cook 1990; Cook 1989a; Wegner and Zdonik 1988]: If I have seen a little farther than others, it is because I have stood on the shoulders of giants. R 5 P % DR. —ISAAC NEWTON In this maxim, R denotes a newly 2.1 Definitions defined object or class, P denotes the properties inherited from an existing In general, to inherit is to receive prop- object or class, DR denotes the incre- erties or characteristics of another, nor- mentally added new properties that dif- mally as a result of some special rela- ferentiate R from P (the delta part), and tionship between the giver and the Q denotes an operation to somehow receiver [Danforth and Tomlinson combine DR with the properties of P.As 1988]. This broad definition of inheri- a result of this combination, R will con- tance comes from the usage of the term tain all the properties of P, except that in the real world, and at the first con- the incremental modification part DR sideration it seems to have very little to may introduce properties that overlap do with computers. Nevertheless, in the with those of P so as to redefine or context of programming, inheritance defeat (cancel) certain properties of P; was introduced as early as in the end of thus, R may not always be fully compat- the 1960s as a central feature of the ible with P. Compatibility issues will be programming language Simula [Dahl et discussed in Section 2.2.2. al. 1968]. However, Simula’s inheri- There are certain terms and notions tance mechanism was originally known pertaining to inheritance that will be by a different name, concatenation used throughout the article. For in- [Dahl et al. 1972, pp. 202–204; Nygaard stance, in the maxim above, P is known and Dahl 1978], and the intuitively as R’s parent or immediate ancestor;in more appealing term inheritance was class-based systems the corresponding invented some years later. Well-known term is superclass. Similarly, R is P’s ACM Computing Surveys, Vol. 28, No. 3, September 1996 440 • Antero Taivalsaari Figure 1. A simple example of inheritance. child, immediate descendant,orin dow and adds a new variable called title class-based systems its subclass. Inher- plus a method that redefines frame itance relationships are transitive, so drawing. The actual implementation of that a parent or superclass may be a the methods is elided. child or subclass of another object or In its basic form, inheritance can be class. This implies that in addition to characterized formally as record combi- incrementally defined properties, an ob- nation [Bracha and Lindstrom 1992; ject will contain all the properties of its Cardelli 1984; Cook 1989a]. An object or parents, parents’ parents and so on. The a class that inherits the properties of terms ancestor and descendant are used another is viewed as a record which is in the obvious manner to denote the otherwise similar to its parent, but immediate and nonimmediate parents which has been extended with some ad- and children of a class. ditional properties. This record combi- Most modern object-oriented systems nation can take place in several differ- allow inheritance from several parents ent ways, however. For instance, in at the same time. Such inheritance is class-based object-oriented systems (see known as multiple inheritance,asop- Section 3.1) the properties of an object posed to single inheritance discussed are typically located physically in differ- above. As multiple inheritance offers ent places, and this tends to make the considerably more possibilities for in- analysis more complicated. Further- cremental modification than single in- more, other issues such as early binding heritance, a generally accepted view is and encapsulation also encumber the that a modern object-oriented language analysis of inheritance. In general, in- should support it, despite the fact that heritance is not an independent lan- multiple inheritance also introduces guage feature, but it usually operates in many conceptual and technical intrica- tight interaction with other language cies. Issues pertaining to multiple in- mechanisms. heritance will be discussed briefly in the following section. For different defini- 2.2 Conceptual View of Inheritance tions of inheritance, refer to Cardelli [1984]; Cook [1989a]; Wegner [1987]; To attain knowledge, add things every day; to Wegner and Zdonik [1988]. obtain wisdom, remove things every day. As an example of inheritance, con- —LAO-TZU, Tao Te Ching sider the following pseudocode defini- tion (Figure 1). In the example, two A programming language is a notation classes, Window and TitleWindow, are and, as such, serves to record and assist defined. Class Window defines one vari- the development of human thought in a able, frame, and two operations (meth- particular direction. For a notation to be ods) drawFrame and drawContents. effective, it must carry a mental load for Class TitleWindow inherits class Win- the user and must have, among other ACM Computing Surveys, Vol. 28, No. 3, September 1996 On the Notion of Inheritance • 441 properties, economy and the ability to at the basic conceptual modeling rela- subordinate detail [Marcotty and tionships in order to elucidate the role Ledgard 1991].

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    42 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us