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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3ccb707f4c91a5f2 X-Google-Attributes: gid103376,public From: mab@dst17.wdl.loral.com (Mark A Biggar) Subject: Re: Java vs Ada 95 (Was Re: Once again, Ada absent from DoD SBIR solicitation) Date: 1996/10/15 Message-ID: <540t2c$rpo@wdl1.wdl.lmco.com>#1/1 X-Deja-AN: 189638469 references: <1996Oct15.154148.1@eisner> organization: Loral Western Development Labs newsgroups: comp.lang.ada Date: 1996-10-15T00:00:00+00:00 List-Id: In article <1996Oct15.154148.1@eisner> kilgallen@eisner.decus.org (Larry Kilgallen) writes: >In article , mg@dsd.camb.inmet.com (Mitch Gart) writes: >> Brian Rogoff (rogoff@sccm.Stanford.EDU) wrote: >> : Besides GC, which is arguable, no one has >> : listed any *language* advantages of Java over Ada. >> Calling superclass methods is easy in Java and hard in Ada: >> type parent_obj is tagged record ...; >> type parent_ptr is access all parent_obj; >> procedure p(param: access parent_obj); >> type child_obj is new parent_obj with ...; >> type child_ptr is access all child_obj; >> procedure p(param: access child_obj); >> now inside the child's p, to call the parent's p: >> p(parent_obj(param.all)'access); >> is the way to do it. Converting the pointer to parent_ptr won't work because >> the call will dispatch back to the child. This ".all'access" trick is pretty >> painful. In Java the keyword "super" does what's wanted: >> super.p(); >> Calling the parent type's operation is common in OOP and is painful to code, >> and read, in Ada. >Presuming a long body for the child, that Ada code potentially must >be altered in many places if the immediate parent changes. At least >the whole body of code must be inspected if the "quiesce" method is >to invoke the "quiesce" method of the immediate parent, whatever that >may be this month. Some have argued that one should not insert new >generations without reviewing all such code, but for some orderly >environments I claim it is quite reasonable to count on coding >standards having been followed. >Macintosh Object Pascal does this with an "inherited" keyword. There is a simple way to handle the change of immediate super parent in the above. Take the above example: if you wanted to drop an imtermediate type in between parent_obj and child_obj two things must tbe changed: the declaration of child_obj must be changed to mention the new intermediate type and the body of the child version of p must be changed to mention the new intermediate type. Note that you must do the first of these in any case, but the second can be avoided (assuming you know ahead of time that you may want to make a change like this by writing the example like so: type parent_obj is tagged record ...; type parent_ptr is access all parent_obj; procedure p(param: access parent_obj); ... subtype super is parent_obj; type child_obj is new super with ... ; type child_ptr is access all child_obj; procedure p(param: access child_obj); and then write the redispatch call in the child version of p as: p(super(param.all)'access); Now to drop in an imtermediate type the only change you have to make to the child code is to redefine the subtype super. Although a attribute for tagged types 'SUPER would have made this a lot easier. -- Mark Biggar mab@wdl.lmco.com