comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: Freezing question
Date: 1999/07/20
Date: 1999-07-20T00:00:00+00:00	[thread overview]
Message-ID: <7n20f4$t1n$1@nnrp1.deja.com> (raw)
In-Reply-To: 37937E54.8D3AA9F0@mitre.org

In article <37937E54.8D3AA9F0@mitre.org>,
  "Robert I. Eachus" <eachus@mitre.org> wrote:
>     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.
>     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;

That's pretty much what I ended up doing. The only difference is that I
had a "Container" operation to call, so I upcasted Parent to
"Container'Class". I should get a constraint_error if it isn't in
Container'Class.

>     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...

I don't think so. There are operations that Containers need to perform
that don't make sense for all Widgets (eg: Adding a child widget to
manage). There are operations that all Widgets including containers need
to be able to perform (redrawing themselves). Containers are just a kind
of widget that has the extra capability of containing and managing other
widgets. But a Container should be able to contain a widget that is not
itself a container. %-)

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




      reply	other threads:[~1999-07-20  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       ` Dispatching with a child for a parameter? (was: Freezing question) Ted Dennison
1999-07-19  0:00       ` Freezing question Ted Dennison
1999-07-19  0:00         ` Robert I. Eachus
1999-07-20  0:00           ` Ted Dennison [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox