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, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c5ca2cbae60e9fee X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: OO puzzle Date: 1999/12/22 Message-ID: <83qtap$pri$1@nnrp1.deja.com>#1/1 X-Deja-AN: 563770117 References: X-Http-Proxy: 1.0 x22.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed Dec 22 16:13:19 1999 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.6 [en] (WinNT; I) Date: 1999-12-22T00:00:00+00:00 List-Id: In article , Ehud Lamm 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.