From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1ce9b9f0acc99abe,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-08 12:04:30 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!agate!news.ucdavis.edu!library.ucla.edu!news.mic.ucla.edu!news.lmu.edu!eecs2.LMU.edu!RTOAL From: RTOAL@lmumail.lmu.edu (Ray Toal) Newsgroups: comp.lang.ada Subject: type extension vs. inheritance Date: Tue, 6 Dec 1994 22:09:06 Organization: Loyola Marymount University Distribution: world Message-ID: NNTP-Posting-Host: eecs2.lmu.edu Keywords: type extension, inheritance X-Newsreader: Trumpet for Windows [Version 1.0 Rev Final Beta #6] Date: 1994-12-06T22:09:06+00:00 List-Id: 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