comp.lang.ada
 help / color / mirror / Atom feed
* type extension vs. inheritance
@ 1994-12-06 22:09 Ray Toal
  1994-12-09 10:42 ` Robb Nebbe
  1994-12-09 17:04 ` John Volan
  0 siblings, 2 replies; 4+ messages in thread
From: Ray Toal @ 1994-12-06 22:09 UTC (permalink / 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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1994-12-12 15:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-12-06 22:09 type extension vs. inheritance Ray Toal
1994-12-09 10:42 ` Robb Nebbe
1994-12-09 17:04 ` John Volan
1994-12-12 15:43   ` Norman H. Cohen

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