Xref: utzoo comp.object:2547 comp.lang.eiffel:1400 Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!uunet!mcsun!ukc!tcdcs!bofin!cjmchale From: cjmchale@cs.tcd.ie (Ciaran McHale) Newsgroups: comp.object,comp.lang.eiffel Subject: Re: Inheritance and Information Hiding Message-ID: <1991Feb8.171341.19413@cs.tcd.ie> Date: 8 Feb 91 17:13:41 GMT Organization: DSG, Dept. of Comp. Sci., Trinity College, Dublin. Lines: 58 Here's my $0.02 worth on the topic concerning rectangles and polygons. Some people have pointed out that since rectangle doesn't support all the operations which might be performed on a polygon, rectangle should *not* be a subtype of polygon. (Other approaches were also suggested.) Instead, the graphics hierarchy should look like: graphic (base class) /\ / \ / \ rectangle polygon A problem with this approach is that rectangle is certainly similar to polygon in many respects and so we would like to have it derived from polygon so that we can reuse code. Bascially we're torn between two seemingly conflicting issues: 1. We can't have rectangle as a subtype of polygon since add_vertex doesn't make sense when applied to a polygon. 2. We do not want to duplicate code which is common between rectangle and polygon. One way to solve this dilemma is for the language to have two hierarchies rather than just one. There would be a TYPE hierarchy and an IMPLEMENTATION (CODE) hierarchy. Using this scheme, rectangle and polygon can be siblings in the TYPE hierarchy, but rectangle could (if the programmer wanted to) inherit code from polygon in the IMPLEMENTATION heierarchy. TYPE HIERARCHY IMPLEMENTATION HIERARCHY -------------- ------------------------ graphic graphic /\ | / \ | / \ polygon rectangle polygon | | rectangle Note that the IMPLEMENTATION hierarchy does not have to mirror the TYPE hierarchy. The IMPLEMENTATION of rectangle will include the add_vertex operation (inherited from the IMPLEMENTATION of polygon) but this will be "private" since it is not specified in rectangle's TYPE. Ciaran. -- Ciaran McHale "Verbosity says it all" ____ Department of Computer Science, Trinity College, Dublin 2, Ireland. \ / Telephone: +353-1-772941 ext 1538 FAX: +353-1-772204 \/ Telex: 93782 TCD EI email: cjmchale@cs.tcd.ie