From -2820604268527907072
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,fdf5ec91b4c47347
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-02-06 10:25:51 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: o.v@k.ro (O.V.)
Newsgroups: comp.std.c++
Subject: Re: Some features to be added to class-based OO languages
Date: Thu, 6 Feb 2003 18:25:49 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 60
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <59143289.0302060923.185dbc7c@posting.google.com>
References: <59143289.0301271214.4aaeeb32@posting.google.com> <$LrUE6OgquN+EwOI@jgharris.demon.co.uk>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1044555949 11344 10.0.0.1 (6 Feb 2003 18:25:49 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 6 Feb 2003 18:25:49 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18gqiZ-0002wp-00
	for mail2news@news.news.demon.net; Thu, 06 Feb 2003 18:25:48 +0000
X-Received: by mulga.cs.mu.OZ.AU
	id FAA26134; Fri, 7 Feb 2003 05:25:43 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 6 Feb 2003 17:23:57 GMT
X-Spam-Status: No, hits=-8.4 required=5.0
	tests=NOSPAM_INC,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_00_01
	version=2.41
Xref: archiver1.google.com comp.std.c++:17841

john@nospam.demon.co.uk (John G Harris) wrote in message news:<$LrUE6OgquN+EwOI@jgharris.demon.co.uk>...
> In article <59143289.0301271214.4aaeeb32@posting.google.com>, O.V.
> <o.v@k.ro> writes
>   <snip>
> >2.1. Seamless interface conversions
>  <snip>
> >an object
> >should be possible to use as an interface if it has all the methods of
> >that interface.
>   <snip>
> 
> That's a very misleading assumption.

In general, yes. In this case, no.

> Remember the BS example : do you expect
>   void draw();
> to make a picture, fire a six-gun, hand out a poker card, get money out
> of a bank, or what?
> 
> Inheritance provides a unique and unbreakable link from an object's
> semantics to an interface's semantics.

There is a simple and imo final answer to this: permit it at compile
time, don't permit it at run time.

Calling Draw is OK in

Painter painter;
painter.Draw ();

because the call is explicitly done for a Painter object; whereas it
would be wrong, if it were possible, in

void* p = ...; // some object
p->Draw ();    // call Draw at run time 
               // if the pointed object has the method

because you don't know what kind of an object p points to, and hence
what its Draw method does, even if it has one.

Similarly, it is correct to convert the Painter above to an interface
IDraw with the method Draw on it, but it's wrong to convert the void*
p to that same interface, even if the pointed object has a Draw
method.
(Seems like a painter and a pointer are 2 very different things. (:-))
At run time, one should obtain the IPainter interface of the object,
if it provides it, then convert the IPainter pointer to the IDraw
interface, which is OK and which is done at complie time. If IPainter
is not provided by the object, the return pointer is NULL so the
caller can take appropriate action.

O.V.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



