Newsgroups: comp.lang.c++,comp.object,comp.theory,comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel-eecis!gatech!howland.erols.net!vixen.cso.uiuc.edu!feeder.chicago.cic.net!ftpbox!mothost.mot.com!schbbs!news
From: shang@corp.mot.com (David L. Shang)
Subject: Re: Opinions on Ellipse-Circle dilemma?
Reply-To: shang@corp.mot.com
Organization: MOTOROLA 
Distribution: inet
Date: Mon, 10 Feb 1997 15:50:58 GMT
Message-ID: <1997Feb10.155058.11151@schbbs.mot.com>
References: <01bc170a$48124540$081aa482@tecra.natinst.com>
Sender: news@schbbs.mot.com (SCHBBS News Account)
Nntp-Posting-Host: 129.188.128.126
Lines: 101
Xref: glinda.oz.cs.cmu.edu comp.lang.c++:247111 comp.object:60995 comp.theory:17885 comp.lang.smalltalk:51400

In article <01bc170a$48124540$081aa482@tecra.natinst.com> "Roger L. Cauvin"  
<rcauvin@homemail.com> writes:
> jodle <jodle@bix.com> wrote in article <5dm3g8$pr6@news2.delphi.com>...
> 
> > The best answer is that circle and ellipse derive from a third class that
> > provides all the traits common to both classes and none of the traits
> > specific to either.
> 
> In geometry, a circle is an ellipse, but not a stretchable ellipse.  As you
> suggest, a three-class hierarchy is appropriate.  However, the base class
> should be the (non-stretchable) Ellipse class in order to reflect the
> conceptual relationships in geometry.
> 
> 			Ellipse
> 			  /   \
> 			/       \
> 	StretchableEllipse     Circle

Exactly. Jodle and Roger's suggestions should bring an end to this
Ellipse-Circle debate.

I always believe that it is the inproper specification of the superclass
that requires a restriction in subclass and makes the subclass voilate
the (inproper) superclass specification.

If "Ellipse" as a superclass have this specification:

	To be eligible for an ellipse, it must be stretchable.

This inproper specification will exclude a circle to be eligible for an
ellipse.

To be general, we can always find that the fault with the superclass'
specification whenever a restriction is required in subclass. Some
more examples:

   2D point:
	To be eligible for a 2D point, it must have two and only
	two dimensions.

This definition exculdes the eligiblity of any 3D or 4D points.

Unfortunately, many people defines 2D point this way:

	class Point2D
	{
	   function equal(other: Point2D): bool;
	};

The function "equal" assumes that any instance of 2D point exactly
has two (no more) dimensions. Should Point3D be derived from Point2D,
a covariant redefinition of the function equal is required.

The correct way is to create the following class hierarchy:

                   PointAtLeast2D
                       /   \
                     /       \
                 Point2D   PointAtLeast3D
                             /   \
                           /       \
                        Point3D   PointAtLeast4D
                                    ...

Java's array makes the same mistake:

   Animal[]:
	To be eligible for an animal array (Animal[]), it must
	be able to accept any kinds of animal.

This definition will excludes a specific array, say, a lamb array, to
be an animal array, because a lamb array cannot accept any kinds
of animal, say a wolf. Unfortunately, Java allows a lamb array to be
a subtype of animal array.

The correct way is to create the following class hierarchy:

         Array whoes member type has not be bound yet
	   but should be a subtype of Animal
                     /       \
                   /           \
   Array whose member type    Array whoes member type has not be
    is bound to Animal         bound yet, but should be a subtype
      Animal[]                 of farm-raised animal
                                 /       \
                             Lamb[]      ...

For details in theorectic aspects, language descriptions, and
more examples, the following papers are available:

 1. Covariant Deep Subtype Reconsidered
    ACM Sigplan Notices, May, 1995.

 2. Are Cows Animals?
    http://www.sigs.com/publications/docs/oc/9601/oc9601.c.shang.html
    or, http://www.transframe.com/document/document.htm

David Shang

	

