home *** CD-ROM | disk | FTP | other *** search
/ ftp.umcs.maine.edu / 2015-02-07.ftp.umcs.maine.edu.tar / ftp.umcs.maine.edu / pub / WISR / wisr6 / proceedings / ascii / edwards.ascii < prev    next >
Text File  |  1993-10-19  |  22KB  |  439 lines

  1.  
  2.  
  3.  
  4.  
  5.               Inheritance:  One  Mechanism,  Many  Conflicting  Uses
  6.  
  7.  
  8.  
  9.                                                  Stephen H. Edwards
  10.  
  11.  
  12.  
  13.                             Department of Computer and Information Science
  14.  
  15.                                              The Ohio State University
  16.  
  17.                                                2036 Neil Avenue Mall
  18.  
  19.                                                 Columbus, OH 43210
  20.  
  21.                                                  Tel: (614) 447-9803
  22.  
  23.                                        Email:  edwards@cis.ohio-state.edu
  24.  
  25.  
  26.  
  27.                                                          Abstract
  28.  
  29.  
  30.            Inheritance has many beneficial uses, but merging them all into a single hierarchy can bring
  31.        out serious conflicts.  The reasons there are such conflicts, and the reasons why they are com-
  32.        monly allowed in oo languages can be seen by examining the different applications of inheritance,
  33.        and who makes use of them. To illustrate this point, this position paper includes a rudimentary
  34.        taxonomy of the various uses for inheritance in oo programming. The primary partition in the
  35.        taxonomy, between inheritance as used by the implementer of a class or as used by the client
  36.        of a class, helps to point out the ways various uses of inheritance can conflict, and can hamper
  37.        effective programming.
  38.  
  39.  
  40.        Keywords:  Inheritance, Object-oriented programming, reuse, sp ecification inheritance, code
  41.        inheritance.
  42.  
  43.  
  44.        Workshop Goals:  Cross-fertilizationof ideas with other researchers; building on the results
  45.        of wisr'92; keeping abreast of other ongoing reuse work; advancing the theoretical foundations
  46.        of software reuse.
  47.  
  48.  
  49.        Working Groups: Design guidelines for reuse, reuse and formal methods, reuse and oo meth-
  50.        ods, reuse handbook.
  51.  
  52.  
  53.  
  54. ___________________________________________________
  55.      This work is supported in part by the National Science Foundation, CCR-9111892.
  56.  
  57.  
  58.                                                         Edwards- 1
  59.  
  60.  
  61. 1      Background
  62.  
  63.  
  64.  
  65. For the past several years,  the Reusable Software Research Group at the Ohio State University
  66. has  been  exploring  the  technical  problems  of  software  reuse,  focusing  on  a  disciplined  approach
  67. to software engineering as a possible solution. In aiming for a discipline of software construction
  68. that will scale up to large systems, the RSRG has centered on the concept of supporting modular
  69. reasoning  or  local certifiability  at  the  component  level  [1 ,  2].  In  short, the  client  of  a  reusable
  70. component or subsystem should only have to consider a b ounded amount of information (i.e., local,
  71. rather than global) when reasoning about whether that component is the correct oneto choose,
  72. and whether it is being used correctly. [3 ] describes one way to ensure that all components have
  73. this property, by applying asp ecific software discipline.
  74.  
  75.  
  76. For  most  oo  languages  in  use  today,  programmers  are  likely  to  take  modular  reasoning  about
  77. classes  as  a  given.  Unfortunately, the  inheritance  mechanism  as  it  is  most  commonly  realized
  78. actually prevents reasoning about classes in a modular fashion, often in very subtle ways [4 ].  It
  79. is possible to overcome this problem by only usinginheritance in a disciplined way. This position
  80. paper explores some of the reasons for the conflicts between inheritanceand mo dular reasoning,
  81. which are actually conflicts between different ways that inheritance is used in programming, and
  82. in reasoning about classes.
  83.  
  84.  
  85.  
  86. 2      Position
  87.  
  88.  
  89.  
  90. Inheritance, which allows new items to be defined with respect to already existing items, is now
  91. widely  used  in  software  construction.  In  fact,  inheritance  is  almost  universally  regarded  as  a
  92. cornerstone  of  methods  termed  "object-oriented"  [5].  One  reason  for  the  success  of  inheritance
  93. is the fact that it meshes with human cognitive abilities_new entities are defined by saying how
  94. they are different from existing entities, which isvery similar to the way people seem to learn by
  95. association, learn rules of generality,and learn exceptions to such rules.
  96.  
  97.  
  98. In a programming context, inheritance has many beneficial uses, but merging them all into a single
  99. hierarchy can bring out serious conflicts.  Many OO practitioners know thatcertain inheritance
  100. practices are not advisable, such ashiding or removing methods in descendant classes, or arbitrarily
  101. redefining method semantics, because subclasses that do not behave asexp ected may be produced.
  102. What is the real reason for such conflicts, and why are they allowed in current oo programming
  103. languages?  An answer can be found by examining the different applications of inheritance, and
  104. who makes use of them.
  105.  
  106.  
  107. Figure 1 depicts a taxonomy of the various uses for inheritance in object oriented programming
  108. (oop). This taxonomy is not meant to be exhaustive, but it does illustrate several interesting divi-
  109. sions. The primary partition in this figure is between inheritance in the implementer's dimension
  110. and inheritance in the user's dimension [6].  From the implementer's p erspective,  inheritance  has
  111. many uses in creating or defining new modules, classes, or objects. From the client's perspective,
  112. inheritance has many uses in understanding, applying, and reasoning ab out classes.
  113.  
  114.  
  115. Note that for the remainder of this discussion, Iwill use the term class to denote a software artifact
  116. defined within an inheritance framework. Similarly, the terms child class or subclass will be used
  117. to  refer  to  a  software  artifact  that  inherits  from  some  parent  class  or  superclass.  I have chosen
  118. these terms since they are commonly used and understood, but I do not wish to imply that only
  119. class-based inheritance systems will be considered [6].
  120.  
  121.  
  122.                                                         Edwards- 2
  123.  
  124.  
  125.  
  126.  
  127.  
  128.                                           __________________
  129.  
  130.                                                  Typesof
  131.                                               Inheritance
  132.                                           __________________ _
  133.  
  134.                            #    _______________________________________     
  135.  
  136.                  ___________________                              ___________________
  137.  
  138.                            How                                             How
  139.                       Classes are                                      Classesare
  140.                  ______Created______ _                            ________Used________
  141.  
  142.                  #    __________                             #   ____________________      
  143.  
  144.           _______________    _______________         _______________              _______________
  145.  
  146.                Sp ecifi-         Implemen-                  In the                         By
  147.                cation             tation                Language                       People
  148.           ________________   _______________ _       _______________ _            _______________ _
  149.  
  150.        #    __________                             #    __________     
  151.  
  152. _______________    _______________          ______________    _________________
  153.  
  154.  
  155.     Behavior            Interface              Execution          fTypeoCon-rmance
  156. ________________   _______________ _        ______________ _  __________________
  157.  
  158.                                                                         #    __________________________     
  159.  
  160. _______________    _______________          ______________     _______________   _________________    _______________
  161.  
  162.      Abstract           Deferred                Dynamic                Is-A           Specialize/           "Like"
  163.      Mo dels            Classes                 Binding           (Subtype)          Generalize
  164. ________________   _______________ _        ______________ _   ________________  _________________ _  ________________
  165.  
  166.  
  167.  
  168.                                  Figure 1:  A Taxonomy of Uses for Inheritance
  169.  
  170.  
  171.  
  172.                                                         Edwards- 3
  173.  
  174.  
  175. From  the  implementer's  perspective, inheritance  is  often  used  as  a  method  of  programming  by
  176. difference. This programming style allows implementers to define new classes differentially, simply
  177. by capturing how they differ from some pre-existing class.  Traditionally,  this capability has been
  178. put forth as one of the key benefits provided by oo languages, and as one of the main sources of
  179. reuse in oo environments.
  180.  
  181.  
  182. The implementer can use inheritance to define the specification of a newclass, the implementation
  183. of  a  new  class,  or  both.  Further,  when  defining  the  specification  of  a  class  by  difference,  the
  184. implementer can treat the parent class in one of two separate ways:
  185.  
  186.  
  187.  
  188.     fflThe specification of the parent class defines a syntactic interface or protocol. The same inter-
  189.        face, with p ossible variations in behavior, will be inherited by the subclass.  This technique
  190.        is often used in event-driven frameworks, where the inherited interface defines the call-back
  191.        points  the  framework  will  use  to  invoke  class-specific  behaviors, without  restricting  what
  192.        those class-specific behaviors might be.   Virtual or deferred class definitions are one way of
  193.        providing such a syntactic interface description in C++ or Eiffel.
  194.  
  195.  
  196.     fflThe specification of the parent class defines a behavioral interface, possibly through the use
  197.        of an abstract model of object state.  This same behavioral description will be inherited by
  198.        the subclass.  This is usually the stance taken when one wants to equate a subtype relationship
  199.        with the subclass relationship.  This type of inheritance can be further restricted by requiring
  200.        that the subclass have the same abstract model as the superclass, rather than simply requiring
  201.        that the behavior be the same.
  202.  
  203.  
  204.  
  205. From the client's perspective, inheritance is not used to define new classes, it is used to understand
  206. and apply existing classes.  Inheritance can be used within the language definition todetermine
  207. how classes can be used in language constructs.  In this vein,  inheritance is most often used for
  208. two  purposes.  First,  it  is  used  in the  execution  model  for  many  oo  languages  to  describe  the
  209. notion of dynamic binding, and how that determines what code operations are executed. Second,
  210. inheritance is very commonly used to determine type conformance for parameters to operations.
  211. Most languages that use this approach choose to interpret inheritance relations as "is-a" or subtype
  212. relations.  A class B is a subtype of another class A (B is-a A) if any instance of B can be used
  213. wherever instances of A are required [6].  The combination of subtyping and dynamic binding is
  214. often the key to providing polymorphism in oo languages.
  215.  
  216.  
  217. In addition to defining the way classes are used within language constructs, inheritance can also
  218. be used to enhance the way people reason about and use classes.  In [6], three distinct forms of
  219. inheritance that are useful for clients are described: is-a relationships, specialization (or generaliza-
  220. tion) relationships, and "like" or similarity relationships. The is-a relation that has already been
  221. described can clearly be used by clients to lowerthe cognitive load of reasoning about collections
  222. of classes. A similar relation, that a class B is a specialization of another class A, can also be used
  223. by clients as an aid to understanding. A class B is a specialization of A if the instances of B can
  224. be obtained from those of A through some form of restriction. [6 ] gives the following examples of
  225. specialization:
  226.  
  227.  
  228.  
  229.        : : :Strings  can  be  viewed  as  specializations  of  arrays  in  which  the  elements must  be
  230.        characters, arrays can be viewed as specialization[s] of dictionaries in which the keys
  231.        (subscripts) must be positive integers.  [6, p.  219]
  232.  
  233.  
  234.  
  235. Finally, the "like" relationship implies that two classes are the same except for some clearly de-
  236. lineated differences.  A set is like a bag, but it does not permit duplicates to be inserted.  This
  237.  
  238.  
  239.                                                         Edwards- 4
  240.  
  241.  
  242. relation can be used to structure a collection of classes into a hierarchy that promotes understand-
  243. ing and careful "chunking" of differences (as opposed to a hierarchy set up for strict subtyping, or
  244. for defining specifications by difference).
  245.  
  246.  
  247. Note  that  in  typical  practice  (e.g.,  C++,  Eiffel),  an oo  language  only  only  supports  a  single
  248. inheritance  hierarchy  and  all  of  these  alternatives are  blended  together  in  this  single  language
  249. mechanism. Programmers working in oo environments most likely focus on inheritance as a balance
  250. between a subtype hierarchy, a code inheritance hierarchy, and a (syntactic) interface inheritance
  251. hierarchy.
  252.  
  253.  
  254. From the point of view of supporting modular reasoning about programs, the uses of inheritance
  255. depicted in Figure 1 pose many challenges. When reasoning about the correctness of a given class
  256. C, one must wear the hats of both implementer andclient:
  257.  
  258.  
  259.  
  260.     fflTo  reason  about  the  correctness  of  a  class  C (which  consists  of  a  specification  and  imple-
  261.        mentation),  one must consider the other classes (and inheritance relations) that went into
  262.        defining the interface and code that realize C.
  263.  
  264.  
  265.     fflTo reason about the correctness of the code realizing the class C, one must also consider the
  266.        classes that C is a client of.
  267.  
  268.  
  269.  
  270. Thus, all of the uses of inheritance in Figure 1 must be considered_not just those seen from the
  271. client's perspective.
  272.  
  273.  
  274. Unfortunately, formal treatments of inheritance often center around an is-a interpretation of the
  275. inheritance  hierarchy,  which  fails  to  address  all  of  the  inheritance  uses  discussed  above.   This
  276. interpretation is also at odds with the way inheritance is used in practice.  If the interpretation
  277. were  correct, and  only  true  is-a  relations  were  permitted  in  an  inheritance  hierarchy,  modular
  278. reasoning would then be feasible. This is the approach taken in resolve, where an implementer
  279. may only make use of inheritance through a very tight interpretation of abstract model specification
  280. inheritance  (at  the  lower  left  of  Figure  1).   This  restriction  ensures  that  the  single  inheritance
  281. hierarchy present can only contain is-a relations.
  282.  
  283.  
  284. Most often, however, this restriction is notmade.  A typical oo language like Smalltalk, C++, or
  285. Eiffel contains a single inheritance mechanism which is used for many (or even all) of the purposes
  286. described in Figure 1.  This hopelessly muddles inheritance of implementation orrepresentation
  287. details with the more abstract inheritance relations like subtyping.  As a result,mo dular reasoning
  288. is not feasible, since the inheritance relationship itself does not have a stable meaning.
  289.  
  290.  
  291. Further, class-based oo systems like Smalltalk, C++, and Eiffel pose specific problems for modular
  292. reasoning:
  293.  
  294.  
  295.  
  296.        In general, a class mechanism enforces the restriction that all objects of a specific class
  297.        have the same representation.  [6, p.  214]
  298.  
  299.        Neither [class-based system] separates the two notions of specification and implementa-
  300.        tion completely because there is always a one-to-one correspondence between the two.
  301.        [6 , p. 227]
  302.  
  303.  
  304.  
  305. The intertwining of specification and implementation concepts within a language can hamper mod-
  306. ular reasoning because it allows implementation details to "creep in" to specifications.
  307.  
  308.  
  309.                                                         Edwards- 5
  310.  
  311.  
  312. In C++ and Eiffel, deferred or virtual classes are used tofurther separate specifications and imple-
  313. mentations by placing the specification in a (virtual) superclass distinct from the concrete imple-
  314. mentation (in a subclass). Disciplined use of this technique can remove the blurring of specifications
  315. and implementations inherent in class-based inheritance, but does not completely address the other
  316. problems limiting modular reasoning.
  317.  
  318.  
  319. It appears that it might be possible to support modular reasoning within an inheritance framework,
  320. but only if conflicting uses of inheritance are decoupled byplacing them in distinct hierarchies, and
  321. if  the  guarantees  that  must  be  made  about  information  hiding  along  inheritance  relations  are
  322. completely spelled out.  Without this approach, it appears that the scope of uses for inheritance
  323. must be significantly limited to make modular reasoning feasible.
  324.  
  325.  
  326.  
  327. 3      Comparison
  328.  
  329.  
  330.  
  331. The central theme in Section 2 is separating the mechanism of inheritance from the ends it can be
  332. used to achieve.  As in most cases where there is more than one possible goal, conflicts between
  333. goals arise.  A language designer who wishes to ensure the correctness of his typing system may
  334. choose  to  restrict  inheritance  in  certain  ways  [7 ,  4]  to  achieve  this,  which  may  in turn  prevent
  335. some programmers from achieving other goals (certain kinds ofco de inheritance).  Alternatively, a
  336. programmer may prefer to arrange his classes in a way that best exploits code sharing, which may
  337. interfere with a user's ability to cleanly understand and reason about the class hierarchy.
  338.  
  339.  
  340. In [6],  many of these same conflicts are raised.  In the end,  LaLonde concludes that (arbitrarily
  341. many) distinct inheritance hierarchies are neededto separate the different inter-class relationships
  342. that are being captured. However, in [6], it is the actual conflicts of different inheritance practices
  343. that  drives  the  discussion_the  goals  that  drive  the  practices  emerge  from  the  discussion  of  the
  344. conflicts, rather than the other way around.
  345.  
  346.  
  347. As mentioned in Section 2, attempting to apply formal methods in an oo environment forces this
  348. problem into the open.  Most often, the approach of researchers is to give a formal definition of
  349. inheritance that has "good" properties, and then restrict inheritance to such uses [8 , 4 , 9 ]. In some
  350. cases, authors have even recommended separating the inheritance hierarchy used for type checking
  351. (i.e., the "specification" inheritance hierarchy) from that used for code sharing [10 ]. Unfortunately,
  352. few, if any, of these approaches is based on the goals that inheritance is used to achieve_instead,
  353. they are often based on a single conception of a "good" inter-class relationship. Fortunately, all
  354. of these approaches tend to choose "good" inheritance relations that ensure modular reasoningis
  355. possible.
  356.  
  357.  
  358. By focusing on "what" programmers and clients wantto do with inheritance,  instead of simply
  359. the  "how"  of  the  inheritance  mechanism  itself,  one  can  step  back  from  the  problem  and  gain  a
  360. slightly  different  perspective.  It  is  clear  that  some  of  the  "whats"  require  conflicting  properties
  361. of the inheritance relationship itself.  Perhaps as LaLonde and others have recommended,  using
  362. distinct hierarchies (or lattices) for separate inter-class relationships is the way to go. Of course, by
  363. examining the support needed for each application of inheritance, one will find thatthere will be
  364. unique restrictions and requirements for these distinct lattices.  Exploring what those requirements
  365. are, and how the lattices should be interrelated, is an arearip e for research.
  366.  
  367.  
  368.  
  369.                                                         Edwards- 6
  370.  
  371.  
  372. References
  373.  
  374.  
  375.  
  376.   [1] B. W. Weide, W. F. Ogden, and S. H. Zweb en,"Reusable software components," in Advances
  377.       in Computers (M. C. Yovits, ed.), Academic Press, 1991.
  378.  
  379.  
  380.   [2] B. W. Weide and J. E. Hollingsworth, "Scalability of reuse technology to large systems requires
  381.       local certifiability," in Proceedings of the Fifth Annual Workshop on Software Reuse, October
  382.       1992.
  383.  
  384.  
  385.   [3] J. Hollingsworth, Software Component Design-for-Reuse: A Language Independent Discipline
  386.       Applied  to  Ada.  PhD thesis,  Dept.  of  Computer  and  Information  Science,  The  Ohio  State
  387.       University, Columbus, OH, 1992.
  388.  
  389.  
  390.   [4] F. Weber, "Getting class correctness and system correctness equivalent," Tech. Rep. ProSt/91-
  391.       4, Forschungszentrum Informatik an der Universit{t Karlsruhe, 1991.
  392.  
  393.  
  394.   [5] R.  G.  Fichman  and  C.  F.  Kemerer, "Object-oriented  and  conventional  analysis  and  design
  395.       methodologies," Computer, pp. 22-39, October 1992.
  396.  
  397.  
  398.   [6] W. R. LaLonde, "Designing families of data types using exemplars," ACM  Transactions on
  399.       Programming Languages and Systems, vol. 11, pp. 212-248, April 1989.
  400.  
  401.  
  402.   [7] B. Meyer, Object-OrientedSoftware Construction. New York, NY: Prentice Hall, 1988.
  403.  
  404.  
  405.   [8] J. C. Royer, "A new set interpretation of the inheritance relation and its checking,"  OOPS
  406.       Messenger, vol. 3, pp. 22-40, July 1992.
  407.  
  408.  
  409.   [9] F. Weber, "Towards a discipline of class composition," Tech. Rep. ProSt/92-3, Forschungszen-
  410.       trum Informatik an der Universit{t Karlsruhe, 1992.
  411.  
  412.  
  413. [10]  P.  S.  Canning,  W.  R.  Cook,  W.  L.  Hill,  and  W. G.  Olthoff,  "Interfaces  for  strongly-typed
  414.       object-oriented programming," in OOPSLA'89 Proceedings, ACM, October 1989.
  415.  
  416.  
  417. [11]  O. L. Madsen, B. Magnusson, and B. M|ller-Pedersen, "Strong typing of object-oriented lan-
  418.       guages revisited," in OOPSLA ECOOP '90 Proceedings, ACM, October 1990.
  419.  
  420.  
  421.  
  422. Biography
  423.  
  424.  
  425.  
  426. Stephen  H.  Edwards  is  a  doctoral  student  in  the  Department  of  Computer  and  Information
  427. Science at the Ohio State University.  His research interests are in software engineering, the use of
  428. formal methods in programming languages, and informationretrieval technology. The current focus
  429. of his work is on developing and refining a formalmo del of software components which explicitly
  430. addresses reuse concerns. Prior to entering the Ohio State University, Mr. Edwards was a research
  431. staff member at the Institute for Defense Analyses, where he worked on software reuse activities,
  432. simulation frameworks, active databases,and Ada programming issues.  Mr.  Edwards received his
  433. MS in computer science from Ohio State in 1992, and his BS in electrical engineering from Caltech
  434. in 1988.
  435.  
  436.  
  437.  
  438.                                                         Edwards- 7
  439.