comp.lang.ada
 help / color / mirror / Atom feed
From: RTOAL@lmumail.lmu.edu (Ray Toal)
Subject: type extension vs. inheritance
Date: Tue, 6 Dec 1994 22:09:06
Date: 1994-12-06T22:09:06+00:00	[thread overview]
Message-ID: <RTOAL.6.00162786@lmumail.lmu.edu> (raw)

Hi,

I have always been under the impression that using C++-style
"inheritance" (derived classes) should ONLY ONLY be used for
situtations in which an IS-A relationship existed between the
derived class and the base class.

Ada 9X has "type extension" and in the Rationale I saw an example
where a 3-D box was derived from a 2-D rectangle by adding a
"depth" field to the width and the height.

1.  Is this something one would really do in practice, or was
    it just an example to illustrate type extension?  I would
    be very nervous using derivation for anything other than
    inheritance, and certainly a parallelpiped IS-NOT-A rectangle.

2.  But even if the answer to (1) is "just an example" a better
    question is, in industry, how many applications REALLY benefit
    from these IS-A hierarchies anyway??  Rosen's paper in the
    1992 CACM Ada special issue on why Ada 83 does not have C++
    style inheritance made a good case for considering classification
    secondary to "composition".

3.  And how would one, in Ada 9X, implement in a nice way the
    derivation of a square from a rectangle?  Am I on the right
    track here?

    package Shapes is

      type Figure is abstract tagged record;
      procedure Move (F: in out Figure; X, Y: Float);
      function Area (F: Figure) return Float is abstract;
      type Rectangle is new Figure with private;
      function Make_Rectange (W, H: Float) return Rectangle;
      function Area (R: Rectangle) return Float;
      type Square is new Rectangle with private;
      function Make_Square (Side_Length: Float) return Square;
      -- area for square inherited from rectangle

      ...

Thanks

Ray Toal




             reply	other threads:[~1994-12-06 22:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-12-06 22:09 Ray Toal [this message]
1994-12-09 10:42 ` type extension vs. inheritance Robb Nebbe
1994-12-09 17:04 ` John Volan
1994-12-12 15:43   ` Norman H. Cohen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox