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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,35b23727c41f3e62 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-30 10:34:59 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn1feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3D46CE25.5010102@worldnet.att.net> From: Jim Rogers User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: en-us MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Multiple interface inheritance workaround in Ada 95 / Ada 0x to satisfy a Java language advocate? References: <1028042914.262359@master.nyc.kbcfp.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 30 Jul 2002 17:34:59 GMT NNTP-Posting-Host: 12.86.35.67 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1028050499 12.86.35.67 (Tue, 30 Jul 2002 17:34:59 GMT) NNTP-Posting-Date: Tue, 30 Jul 2002 17:34:59 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:27486 Date: 2002-07-30T17:34:59+00:00 List-Id: 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(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