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,8660fe29f138b478 X-Google-Attributes: gid103376,public From: "Robert I. Eachus" Subject: Re: Freezing question Date: 1999/07/19 Message-ID: <37937E54.8D3AA9F0@mitre.org>#1/1 X-Deja-AN: 502832014 Content-Transfer-Encoding: 7bit References: <7mlg18$qk0$1@nnrp1.deja.com> <378E57FE.FA7EEB99@averstar.com> <7mnc3q$f6r$1@nnrp1.deja.com> <379347D8.A902583C@averstar.com> <7mvp0h$333$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@news.mitre.org X-Trace: top.mitre.org 932412877 14423 129.83.41.77 (19 Jul 1999 19:34:37 GMT) Organization: The MITRE Corporation Mime-Version: 1.0 NNTP-Posting-Date: 19 Jul 1999 19:34:37 GMT Newsgroups: comp.lang.ada Date: 1999-07-19T19:34:37+00:00 List-Id: Ted Dennison wrote: > > > Ahhh. I bet that's it. Does that mean that in the example above, Apple > > > will inherit *none* of Fruit's operations, since none of them were > > > declared before Apple? > > > > Correct. See 7.3.1(7). (Well, actually it will inherit any implicit operations created by the declaration. In this case it gets "=".) > Ahhh. OK. So then next question: > How would one implement a hierarchy where one object needs dispatching > operations that take a specific one of its chilren types as parameters? > I'm running out of ideas. The usual is either to declare a class wide operation, and dispatch in the body or to define the operation over a wider scope than necessary and raise an exception when necessary. > eg: > > type Widget is abstract tagged private; > type Container is abstract new Widget with private; > > procedure Add > (Child : in out Widget; > Parent : in out Container'Class > ); > > Won't quite work because Add won't be inherited by any Containers unless > it is placed before the declaration of Container. But if I move it > between the two declarations, it won't compile because Container won't > have been declared yet. Semantically, having the class of the parent derived from the child doesn't make sense in all cases anyway, so I would do the following: type Widget is abstract tagged private; procedure Add (Child : in out Widget; Parent : in out Widget'Class); type Container is abstract new Widget with private; ... procedure Add (Child : in out Widget Parent : in out Widget'Class) is begin if not Parent in Container'Class then raise ... end if; Of course, IMHO, you want Widget and Container to be related so that Parent is actually a wider class than Widget, but that is another issue... -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...