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 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-09 12:09:37 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!gatech!udel!news.mathworks.com!zombie.ncsc.mil!paladin.american.edu!newsfeed.ACO.net!swidir.switch.ch!epflnews!dinews.epfl.ch!lglsun!nebbe From: nebbe@lglsun.epfl.ch (Robb Nebbe) Newsgroups: comp.lang.ada Subject: Re: type extension vs. inheritance Date: 9 Dec 1994 10:42:30 GMT Organization: Ecole Polytechnique Federale de Lausanne Sender: nebbe@lglsun3.epfl.ch (Robb Nebbe) Distribution: world Message-ID: <1994Dec9.103927@lglsun.epfl.ch> References: NNTP-Posting-Host: lglsun3.epfl.ch Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Keywords: type extension, inheritance Date: 1994-12-09T10:42:30+00:00 List-Id: In article , RTOAL@lmumail.lmu.edu (Ray Toal) writes: |> |> 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? In my opinion it is more an example of what you can do than what you should do (but I didn't write the Rationale so I don't know what they think). |> 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?? If you need to implement a hierarchies of abstractions then inheritance is the way to do it. It is cleaner, easier to modify and maintain. There are two main uses for these hierarchies: 1. They better document the structure of the software thus facilitating its maintenance and extension but dispatching (polymorphism) is not used. 2. You need to refer to a class of abstractions. How necessary this is depends a lot on the domain you are working in but in most cases I find that composition is a more common mechanism than classification. |> 3. And how would one, in Ada 9X, implement in a nice way the |> derivation of a square from a rectangle? There are two ways to model this, semantically what you want is something close to (* see note): type Rectangle is private; subtype Square is Rectangle; but classification is probably best used like: type Four_Sided is abstract tagged private; type Quadrilateral is new Four_Sided with private; type Parallelogram is new Four_Sided with private; type Rectangle is new Four_Sided with private; type Square is new Four_Sided with private; and then declare conversion functions between different types to represent overlaping domains, which is not necessarily the same as a subtype. Robb Nebbe *note: The problem is that you can't associate the necessary predicate with the subtype Square like you can with numeric types so you would probably declare a function Is_Square and distribute the complexity of testing a rectangle to see if it is square acrossed the clients. It might be worth looking into extending the pragma Assert in GNAT to do this but this is pure speculation.