method returning child, doesn't overrides declared method returning parent

Mariusz Gliwiński alienballance at gmail.com
Mon Aug 29 15:18:35 PDT 2011


Jonathan M Davis wrote:
> It's _not_ overriding. It's implementing [...]

Whether it's called overriding or implementing isn't a big deal for me. In D 
we *already* write _override_ keyword to _implement_ method (IMO it's good 
choice, to match with overriding class methods).


But back to the topic, it would be like that:
* we have object which implements interface
* we have method that returns objects implementing this interface
* we want to return object which implements this interface
* we can't return it as class (implementation of interface + something 
more), because we have to be seen ONLY as implementation of this interface

result:
We have to declare method, that returns child object, then make a proxy to 
narrow and override interface. So it looks like:
<code>
Class real_method() {}
override Interface method() {stupid_method();}
</code>

Ps. If someone felt offended by calling "object, that implements interface" 
a "child object", i'm sorry for that.

Thanks,
Mariusz Gliwiński


More information about the Digitalmars-d mailing list