From: "Robert I. Eachus" <eachus@mitre.org>
Subject: Re: Freezing question
Date: 1999/07/19
Date: 1999-07-19T19:34:37+00:00 [thread overview]
Message-ID: <37937E54.8D3AA9F0@mitre.org> (raw)
In-Reply-To: 7mvp0h$333$1@nnrp1.deja.com
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...
next prev parent reply other threads:[~1999-07-19 0:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-07-15 0:00 Freezing question Ted Dennison
1999-07-15 0:00 ` Tucker Taft
1999-07-16 0:00 ` Ted Dennison
1999-07-19 0:00 ` Tucker Taft
1999-07-19 0:00 ` Ted Dennison
1999-07-19 0:00 ` Robert I. Eachus [this message]
1999-07-20 0:00 ` Ted Dennison
1999-07-19 0:00 ` Dispatching with a child for a parameter? (was: Freezing question) Ted Dennison
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox