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: kilgallen@eisner.decus.org (Larry Kilgallen) Subject: Invoking parental methods (was: Java vs Ada 95) Date: 1996/10/29 Message-ID: <1996Oct29.070337.1@eisner>#1/1 X-Deja-AN: 192965894 x-nntp-posting-host: eisner.decus.org references: <5536en$2vk@nntpa.cb.lucent.com> x-nntp-posting-user: KILGALLEN x-trace: 846590649/702 organization: LJK Software newsgroups: comp.lang.ada Date: 1996-10-29T00:00:00+00:00 List-Id: I apologize for the following long quote, but "who said what to whom gets messy here". In article <5536en$2vk@nntpa.cb.lucent.com>, ka@socrates.hr.att.com (Kenneth Almquist) writes: > mg@dsd.camb.inmet.com (Mitch Gart) wrote: >> 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. > > No it won't. Dispatching only occurs when you use class-wide types.[1] > > You don't explain why you are using access types. Normally you would > write: > > type parent_obj is tagged record ...; > procedure p(param: in out parent_obj); > > type child_obj is new parent_obj with ...; > procedure p(param: in out child_obj); > > Now inside the child's p, to call the parent's p: > > p(parent_obj(param)); > > This reads quite well (or at least it would if parent_obj had a meaningful > name). > Kenneth Almquist > > > [1] You don't want to convert to parent_ptr because of the possibility > of accessibility errors. Instead use a pointer type declared in p: > > procedure p(param: access child_obj) is > type super is access all parent_obj; > begin > ... > p(super(param)); -- call the parent's p > ... > end p; Declaring a pointer type within p does not meet the requirement of minimizing the change required when an intermediate generation gets inserted and there are many such invocations. Why can't it be declared at the top of the package ? Larry Kilgallen