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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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? Eiffel 3 fixes this bug--by allowing heirs to restrict exports from parents:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/06/2008 for the course CSE 432 taught by Professor Blank during the Fall '08 term at Lehigh University .

Page1 / 7

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online