From: Ted Dennison <dennison@telepath.com>
Subject: Re: OO puzzle
Date: 1999/12/22
Date: 1999-12-22T00:00:00+00:00 [thread overview]
Message-ID: <83qtap$pri$1@nnrp1.deja.com> (raw)
In-Reply-To: Pine.A41.3.96-heb-2.07.991222103646.28794B-100000@pluto.mscc.huji.ac.il
In article
<Pine.A41.3.96-heb-2.07.991222103646.28794B-100000@pluto.mscc.huji.ac.il
>,
Ehud Lamm <mslamm@mscc.huji.ac.il> wrote:
> This example is again from the Eiffel book.
>
> 1. Truck_Driver IS-A Driver (one hierrachy)
>
> 2. Motor_Vehicle (and all its kids) support the operation
> register_Driver(d:driver) the paramter is of type driver above.
>
> Car IS-A Motor_Vechicle
> Truck IS-A Motor_Vehicle
> Truck wants to override register_driver(d:truck_driver) becuase
> only truck drivers should be allowed here.
>
> Can yuo do this in Ada? Try, and show your error messages! How can you
> do something to achive the same result, in Ada?
Well, I'll assume in Ada you would be talking about a routine that
takes in driver'class and also has a "motor_vehicle" parameter on which
it dispatches, and it does *not* dispatch on the driver. One possibility
would be to have truck's version of register_driver internally check
that the driver is in truck_driver'class:
if d not in truck_driver'class then
raise Constraint_Error;
end if;
Another would be to disallow calls to the original register altogether
(via "abstract" perhaps?) and to make a new one that only takes in
truck_driver'class. That looses the dynamic dispatch from
Motor_Vehicle'class, though.
--
T.E.D.
Sent via Deja.com http://www.deja.com/
Before you buy.
next prev parent reply other threads:[~1999-12-22 0:00 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-12-22 0:00 OO puzzle Ehud Lamm
1999-12-22 0:00 ` Ted Dennison [this message]
1999-12-23 0:00 ` Ehud Lamm
1999-12-23 0:00 ` Ted Dennison
1999-12-25 0:00 ` Ehud Lamm
1999-12-23 0:00 ` Robert A Duff
1999-12-25 0:00 ` Ehud Lamm
1999-12-22 0:00 ` Tucker Taft
1999-12-23 0:00 ` Ehud Lamm
1999-12-23 0:00 ` Robert Dewar
1999-12-23 0:00 ` Ehud Lamm
1999-12-24 0:00 ` swhalen
1999-12-25 0:00 ` Ehud Lamm
1999-12-25 0:00 ` Ehud Lamm
1999-12-29 0:00 ` Brian Rogoff
1999-12-30 0:00 ` Jeffrey L Straszheim
1999-12-31 0:00 ` Brian Rogoff
1999-12-31 0:00 ` Jeffrey L Straszheim
2000-01-02 0:00 ` Brian Rogoff
2000-01-03 0:00 ` Matthew Heaney
1999-12-22 0:00 ` Jeff Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox