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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,760a0492b97ae06e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-20 03:07:19 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!dialin-145-254-040-018.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: How to test object hierarchy Date: Sat, 20 Dec 2003 12:13:35 +0100 Organization: At home Message-ID: References: <93172edb.0312181024.9a536b2@posting.google.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-040-018.arcor-ip.net (145.254.40.18) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 1071918438 8918709 145.254.40.18 ([77047]) User-Agent: KNode/0.7.2 Xref: archiver1.google.com comp.lang.ada:3621 Date: 2003-12-20T12:13:35+01:00 List-Id: Georg Bauhaus wrote: > Dmitry A. Kazakov wrote: > : type Derived_Object is new Root_Object with ...; > : procedure Test_Hierarchy > : ( Obj1 : in Derived_Object; > : Obj2 : in Root_Object'Class; > : Recursion : Boolean := False > : ) is > : begin > : if Recursion > : or else Obj2 not in Derived_Object'Class > : or else Obj2 in Derived_Object > : then > : Do_It (Obj1, Obj2); -- Deal with Obj1 :>= Obj2 > : else > : Test_Hierarchy (Obj2, Obj1, True); -- Dispatch again > : end if; > : end Test_Hierarchy; > : > : You have to override Test_Hierarchy for each new type, but I suppose > : that "do something" in your code is dispatching anyway. When > : Test_Hierarchy is not commutative it gets a bit more complicated, but I > : think you have got the idea. > > Whenever I see an "if" testing for types I'm wondering whether > these ifs should be turned "to the outside" into what they mean > in the solution domain, but using language means. Is it really > advantageous or necessary to have to do manual dispatching in > your program? R-r-right. The rest is easy, just to write an AI for multiple dispatch in Ada! (:-)) Ideally, the language should allow to program without any explicit testing/casting for types. I remember a fierce discussion in comp.object on this topic. The result, as always, was unsettled. Then not always types do reflect the solution domain. In some cases the language rules (limitations) force developer to create helper types. There are also semi-domain types, like pointers, handles, interators etc. > And I have the same question that Hyman has asked about generics, > plus, Should we emulate inheritance using generics? > should "with type" be mentioned in this context? Interesting, why do you thing it should? -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de