10inher - The"meaning of inheritance Semantics of...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The "meaning" of inheritance Semantics of inheritances is shifty ( Overhead: A Hierarchy of Classes ) --a classic paper by Woods on semantic networks: What's in a link? --isa could mean subtype or instance-of or has-properties-of ... See and discuss UM multimedia in problem solving: Square Meyer: depends on how look at classes -- as type or as module 1) Classes as type : --inheritance means subtype E.g., SQUARE is a subtype of RECTANGLE Subtype specializes supertype E.g., SQUARE computes perimeter from just one side 2) Classes as module : inheritance means more services CLOSED_FIGURE adds features to FIGURE: perimeter, area CLOSED_FIGURE, the heir, is an extension of FIGURE I.e., subtype vs. implementation inheritance: but should we use the same mechanism? --in Eiffel, yes: inheritance can be used for semantic or implementation purposes --in Sather, no: distinguishes subtype and implementation inheritance --What about C++? What about Java? Multiple Inheritance (Overhead) Eiffel permits a class to inherit from many superclasses class FIXED_STACK[T] inherit STACK[T]; ARRAY[T] ... end; Meyer calls this a "marriage of convenience" I call this a good example of the ambiguity of the inheritance relation! FIXED_STACK inherits from two classes: NOTE semi-colon (;) STACK[T] is a deferred class: (an "aristocratic family"): defines the semantics of stacks abstractly FIXED_STACK is a specialization of STACK: with fixed size ARRAY[T] is an effective class: (a "bourgeous family") provides implementation details FIXED_STACK is an extension of ARRAY to implement push,pop... LINKED_STACK inherits from a different effective class: LINKED_LIST Is this a good idea? What kinds of relations are being lumped together? Confuses subtype, part-of, implementation relations Does C++ distinguish between subtype and implementation inheritance? How? What about Java? Eiffel encourages using inheritance for implementation purposes (convenience): --STD_FILES, FILES, VIEWABLE, STORABLE, ENVIRONMENT, etc. Has inheritance in Eiffel just become a device for getting non-local scope? How could FIXED_STACK be implemented without multiple inheritance? make ARRAY an attribute of FIXED_STACK--this approach is called delegation 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
A potential problem--consider the following code fragment: s:FIXED_STACK[CHARACTER]; !!s.make; --FIXED_STACK's make creates an ARRAY of some default size s.put('A',3); putchar(s @ 3); --using ARRAY routines from FIXED_STACK What's the problem here? [Violation of semantics of STACK (see ADT axioms)] Information hiding problem: how do we hide ARRAY access from clients of STACKs?
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern