Newsgroups: comp.lang.c++,comp.object,comp.theory,comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!newstand.syr.edu!news.maxwell.syr.edu!news.mathworks.com!howland.erols.net!torn!kwon!watserv3.uwaterloo.ca!undergrad.math.uwaterloo.ca!eadengle
From: eadengle@dino.uwaterloo.ca (Ed "Cynwrig" Dengler)
Subject: Re: Opinions on Ellipse-Circle dilemma?
Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
Message-ID: <E5JzHA.K16@undergrad.math.uwaterloo.ca>
Date: Thu, 13 Feb 1997 18:03:10 GMT
Distribution: inet
References: <5d4fmf$7gk@bagan.srce.hr> <E5B2HH.8AH@ecf.toronto.edu> <E5EMwz.74K@undergrad.math.uwaterloo.ca> <01bc183f$67b8c5a0$543db6cc@victor.imsisoft.com>
Nntp-Posting-Host: dino.uwaterloo.ca
Organization: University of Waterloo
Lines: 89
Xref: glinda.oz.cs.cmu.edu comp.lang.c++:247732 comp.object:61119 comp.theory:17944 comp.lang.smalltalk:51570

Greetings!

In article <01bc183f$67b8c5a0$543db6cc@victor.imsisoft.com>,
Victor Bazarov <vbazarov@imsisoft.com> wrote:
>Hi,
>
>Ed "Cynwrig" Dengler <eadengle@hoporoo.uwaterloo.ca> wrote in article
><E5EMwz.74K@undergrad.math.uwaterloo.ca>...
>> Greetings!
>> 
>> CLASS Ellipse:
>>     METHOD setAxesLength( real major, real minor )
>> 
>> CLASS Circle: SUBCLASS Ellipse
>> 
>> 
>> A: Circle
>> B: Ellipse
>> 
>> A.Create
>> B := A
>> B.setAxesLength( 5, 10 )
>> 
>> Hmmmm, doesn't work too well does it?
>
>No, of course not. I ask you please to excuse me, if I am completely out of
>the field in Smalltalk. But consider this:
>
>(more like pseudocode)
>
>CLASS Ellipse:
>	VIRTUAL METHOD setAxesLength( real major, real minor ) PURE
>
>Implementation:
>	Ellipse::setAxesLength(...) { ... }
>
>CLASS Circle: SUBCLASS Ellipse
>	VIRTUAL METHOD setAxesLength( real major, real minor )
>
>Implementation:
>	Circle::setAxesLength(...) { if (axes same) set radius; else do nothing }
>
>> The problem of matching subtypes is that you also match interfaces, which
>means
>> that any subclass better support what its superclass can be told to do.
>> 
>> Ed
>
>If a language provides the mechanism that REQUIRES to override a method,
>the errors can be avoided. You should slap me if I am completely wrong, my
>knowledge and experience are limited to C++ and Object Pascal. C++ has pure
>virtual functions that still can have implementations (and can be called
>for the class where they're pure virtual). I do not know whether it
>interferes with theory or not.
>
>As far as I understand it, the actual derivation cannot be made if the
>interface is not suitable for that. So, if my Ellipse class has a
>setAxesLength() method, I cannot derive Circle from it right? Same as I
>cannot derive Kiwi (or Penguin if it matters) from a Bird class if it
>(Bird) has a method "Fly()".
>
>Regards,
>
>Victor.

The problem occurs in the above in that if I pass a Circle object to an
Ellipse pointer, the rest of my code expects certain behaviours to be
implemented by the subclass (I believe Bertrand Meyer (?) of Eiffel fame
called this "programming by contract").  For example, if I have a link list
and then I implement a subclass that performs hashing, and the subclass does
_not_ preserve the semantics (such as add to end of list, thus preserving
ordering), then I have not followed the object-oriented paradigm that
subclasses can be treated as their superclass.

So we essentially have a software engineering problem here.  If I (as
the library developer) provide a set of semantic considerations on my
components, then I (as another library developer) should not develop
new code that inherits from that class and breaks the semantic constraints,
thus allowing I (as the application developer) to be able to use the
original class in other places without worries of is it really an Ellipse
or might it be a Circle masquerading as an Ellipse?  The entire software
engineering community has enough headaches without adding this sort of
unnecessary complexity that would most likely break code.

Adding extra constraints may unexpectantly break my code, which the whole
paradigm of object-oriented programming is supposed to prevent.

Ed

