[comp.lang.eiffel] A rectangle is NOT a modifiable polygon

d87-mra@dront.nada.kth.se (Magnus Ramstr|m) (02/03/91)

After reding very many postings on this subject I found an article
adressing the point I had been looking for, so I took the liberty to
change the subject line in order to get the following read by those who
use the kill button.

In article <1081@tetrauk.UUCP> rick@tetrauk.UUCP (Rick Jones) writes:
>In article <488@eiffel.UUCP> bertrand@eiffel.UUCP (Bertrand Meyer) writes:
>>
>>	Will anyone take up the simplest example (discussed in my
>>posting <485@eiffel.UUCP>): a class POLYGON exists and has
>>a procedure ``add_vertex'', which it exports.
>>You want to add a class RECTANGLE. What do you do?
>
>This thread seems to me to be exposing one of the fundamental problems of
>inheritance, which is the distinction between mutable and imutable objects.
>
>Given that inheritance implies both specialisation and extension, then if
>objects are considered fixed once created there is no problem: a rectangle is
>clearly a descendant of polygon, since it is a specialised version. 
>Everywhere that a fixed polygon may be used, then a fixed rectangle may be 
>used, so a rectangle is type conformant with a polygon.
>
>However, when we allow objects to be modified we are seriously challenging the
>whole concept of taxonomy.  In fact in the shapes example, the type 
>conformance appears to be inverted.  In terms of modifying vertices, the 
>polygon is type conformant with a rectangle.
>
When creating a superclass you must think of the possible subclasses. After
all, reuse is not about reusing the code of others only, but just as much 
about making it possible for others to reuse your code. A fixed polygon can
not be in a subclass of the class of modifiable polygons. Think of the given
class POLYGON as having the restriction of forcing objects of subclasses to
be modifiable as well.

So, the given problem is incorrect and from Dr. Meyer's alternatives I choose
#1 (not to use inheritance).

>-- 
>Rick Jones
>Tetra Ltd.  Maidenhead, 	Was it something important?  Maybe not
>Berks, UK			What was it you wanted?  Tell me again I forgot
>rick@tetrauk.uucp					-- Bob Dylan

Well, I found your posting to be what I wanted to read!

d87-mra@nada.kth.se (Magnus Ramstr|m). Student @ Dep. of Computer Science.