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 Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!ucbcad!ucbvax!MITRE-BEDFORD.ARPA!sdl From: sdl@MITRE-BEDFORD.ARPA (Litvintchouk) Newsgroups: comp.lang.ada Subject: Re: Inheritance and Ada (and access types and generics) Message-ID: <8712280109.AA10857@mitre-bedford.ARPA> Date: 28 Dec 87 01:09:18 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet List-Id: In article <255@hub.ucsb.edu> bertrand@hub.ucsb.edu (Bertrand Meyer) writes: > I am surprised none of the discussants quoted my article, ``Genericity > versus Inheritance'', which addresses precisely this topic. The paper > was published in the Proceedings of the first OOPSLA conference > (OOPSLA 86, Portland; SIGPLAN Notices, 21, 11, pp. 391-405). A revised > version is due for publication in the Journal of Pascal, Ada and Modula-2. > > The article explores the relationship between Ada-like generic modules > and inheritance as it exists in O-O languages. It shows the respective > benefits of both techniques and explains how they have been (cleanly, > I think) combined in the Eiffel language and environment. > My apologies, I was at OOPSLA '86 and thought your paper was excellent. (and there have been other good papers on the subject as well.) > This does not prevent data structures from being polymorphic: > for example, if an entity is declared as > > fs: STACK [FIGURE] > > then you may push onto the corresponding object a point, > a circle etc., assuming POINT, CIRCLE > etc. are descendant classes (in the sense of inheritance) of FIGURE. > However you may not push onto fs, say, an integer.... Actually, attempting to simulate this kind of polymorphism in Ada is even clumsier than your paper portrayed it. As you pointed out, you do end up having to define variant record types (whose variants include all the polymorphic subclasses) and other case analyses all over the place. Even worse, however, Ada does not let you instantiate the (generic) STACK package with an unconstrained variant record type, if the package requires the type to be constrained (as is often the case). Thus in Ada, I find I am continually forced to play this game of instantiating the generic with an access (pointer) type to the variant record type. Not only is this clumsy, but it requires you to use allocators ("new") to create the instances of the record type, opening up all the performance issues of using dynamic allocation in embedded computer systems software. Sadly, you are often forced to use access types in Ada, even when you're not particularly interested in dynamic storage, but just to get around some of the quirks of Ada's type model. Another example: you can't instantiate a generic with an incomplete type. So you end up having to fake it by instantiating the generic with an access type that points to the incomplete type, and you can guess the rest. Steven Litvintchouk MITRE Corporation Burlington Road Bedford, MA 01730 Fone: (617)271-7753 ARPA: sdl@mitre-bedford.arpa UUCP: ...{cbosgd,decvax,genrad,ll-xn,philabs,security,utzoo}!linus!sdl