comp.lang.ada
 help / color / mirror / Atom feed
From: Jim Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: Multiple interface inheritance workaround in Ada 95 / Ada 0x to satisfy a Java language advocate?
Date: Tue, 30 Jul 2002 17:34:59 GMT
Date: 2002-07-30T17:34:59+00:00	[thread overview]
Message-ID: <3D46CE25.5010102@worldnet.att.net> (raw)
In-Reply-To: 1028042914.262359@master.nyc.kbcfp.com

Hyman Rosen wrote:

> Jean-Pierre Rosen wrote:
> 
>> Yes. Or more exactly, the design pattern provides functions
> 
>  > that allow you to get an I1 or I2 view for a C object, and to
>  > go back from an I1 or I2 view back to the original C object.
> 
>>
>> And you are correct that this is not obvious to achieve.
> 
>  > That's what prompted me to make a paper of it!
> 
> Going back to the original object isn't quite the same thing.
> It's something of a red herring since this kind of thing is
> extremely rarely used, but you can't claim full conformity
> if you don't support it.
> 
> Here is what this kind of code looks like:
> 
> // Java
> void f(I1 i1) { if (i1 instanceof I2) { I2 i2 = (I2)i1; } }
> 
> // C++
> void f(I1 *i1) { I2 *i2 = dynamic_cast<I2 *>(i1); if (i2) { /*...*/ } }
> 
> As long as the underlying object has an accessible i2 in its
> inheritance graph, the conversion works, and the code does not
> need to know what the common ancestor class is, and will work
> for many different ancestor types.


In Java all classes have an ultimate shared ancestor, the Object
class.


> 
> This is accomplished by compiler magic. The compiler has access
> to the virtual tables and can search them for the presence of
> appropriate bases.
> 

I am not strong on C++ so I will deal with the Java example above.
All Java objects are accessed through references. This is equivalent
to having all Ada object accessed through access to class types.

The Ada equivalent for a tagged type is:

type I1_Access is access all I1'Class;
type I2_Access is access all I2'Class;

procedure f(item : in I1_Access)
    temp : I2_Access;
begin
    if item.all in I2'Class then
       temp := item;
    end if;
end f;

Note that this performs a lookup similar to what you describe.

Jim Rogers




  reply	other threads:[~2002-07-30 17:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-29 12:05 Multiple interface inheritance workaround in Ada 95 / Ada 0x to satisfy a Java language advocate? Colin Paul Gloster
2002-07-29 12:42 ` Jean-Pierre Rosen
2002-07-29 14:18   ` Colin Paul Gloster
2002-07-29 14:58     ` Jean-Pierre Rosen
2002-07-29 17:04       ` Pascal Obry
2002-07-30 13:57   ` Hyman Rosen
2002-07-30 14:27     ` Jean-Pierre Rosen
2002-07-30 15:30       ` Hyman Rosen
2002-07-30 17:34         ` Jim Rogers [this message]
2002-07-30 18:20           ` Hyman Rosen
2002-07-30 20:22             ` Robert A Duff
2002-07-30 19:17           ` Robert A Duff
2002-07-30 22:10             ` Hyman Rosen
2002-07-29 17:27 ` Hyman Rosen
2002-07-30  8:13   ` Dmitry A. Kazakov
2002-07-30 20:55     ` Robert Dewar
2002-07-31 22:08       ` Dmitry A.Kazakov
replies disabled

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