comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: How to test object hierarchy
Date: Sat, 20 Dec 2003 12:13:35 +0100
Date: 2003-12-20T12:13:35+01:00	[thread overview]
Message-ID: <bs1ah5$8g5ll$2@ID-77047.news.uni-berlin.de> (raw)
In-Reply-To: brvc9c$3ne$2@a1-hrz.uni-duisburg.de

Georg Bauhaus wrote:

> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> 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



  reply	other threads:[~2003-12-20 11:13 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-18 18:24 How to test object hierarchy Pierre Favier
2003-12-19  0:15 ` Stephen Leake
2003-12-19  7:45   ` Pierre Favier
2003-12-19 10:53 ` Dmitry A. Kazakov
2003-12-19 14:35   ` Hyman Rosen
2003-12-19 17:07     ` Dmitry A. Kazakov
2003-12-19 23:26     ` Robert A Duff
2003-12-20 18:20       ` Robert I. Eachus
2003-12-19 17:25   ` Georg Bauhaus
2003-12-20 11:13     ` Dmitry A. Kazakov [this message]
2003-12-21  4:34       ` Georg Bauhaus
2003-12-21 13:43         ` Dmitry A. Kazakov
2003-12-21 19:58           ` Dmytry Lavrov
2003-12-22  1:19             ` Robert I. Eachus
2003-12-22 10:09               ` Dmitry A. Kazakov
2003-12-22 17:33                 ` Robert I. Eachus
2003-12-23 10:49                   ` Dmitry A. Kazakov
2003-12-22 10:05             ` Dmitry A. Kazakov
2003-12-19 17:24 ` Nick Roberts
replies disabled

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