www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Class-Interface compatibility

reply Frank Benoit <keinfarbton googlemail.com> writes:
COM is the only reason I am aware of, why interfaces are not implicit 
compatible to to object.Object. But COM is a very special case which 
probably can get a special solution?

How about making /IUnknown/ a special interface without this 
compatibility and have all interfaces, not derived from IUnknown be 
compatible to Object?
Mar 30 2008
parent reply "Scott S. McCoy" <tag cpan.org> writes:
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

It is kind of curious why interface typed identifiers don't implicitly
cast to Object, and you must explicitly cast.

But regardless of the reason, adopting a convention (and a bad one at
that) such as prefixing interfaces with "I" probably shouldn't be done
at the language level.  And even more, D already has avoided creating
any kind of special types (you can throw Object, for instance, and it's
not a derivative of Exception) so far as I can tell...why start now?

Cheers,
    Scott S. McCoy

On Sun, 2008-03-30 at 23:25 +0200, Frank Benoit wrote:

 COM is the only reason I am aware of, why interfaces are not implicit 
 compatible to to object.Object. But COM is a very special case which 
 probably can get a special solution?
 
 How about making /IUnknown/ a special interface without this 
 compatibility and have all interfaces, not derived from IUnknown be 
 compatible to Object?
 
 

Mar 30 2008
parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
[fixed upside-down post]

Scott S. McCoy wrote:
 On Sun, 2008-03-30 at 23:25 +0200, Frank Benoit wrote:
 COM is the only reason I am aware of, why interfaces are not implicit 
 compatible to to object.Object. But COM is a very special case which 
 probably can get a special solution?

 How about making /IUnknown/ a special interface without this 
 compatibility and have all interfaces, not derived from IUnknown be 
 compatible to Object?


 It is kind of curious why interface typed identifiers don't implicitly 
 cast to Object, and you must explicitly cast.
 
 But regardless of the reason, adopting a convention (and a bad one at 
 that) such as prefixing interfaces with "I" probably shouldn't be done 
 at the language level.  And even more, D already has avoided creating 
 any kind of special types (you can throw Object, for instance, and it's 
 not a derivative of /Exception/) so far as I can tell...why start now?

He didn't propose handling interfaces starting with 'I' differently. He proposed handling interfaces derived from IUnknown differently. They're already treated differently[1], but he wanted to change the behavior of other interfaces without adding the same change to IUnknown-derived interfaces (since it wouldn't work there[2]). [1]: See the last part of <http://www.digitalmars.com/d/1.0/interface.html>. [2]: Objects referred to by COM interface references (see [1]) may be implemented in a different language than D, and so may not be compatible with the D Object class at all.
Mar 31 2008