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

Jonathan M Davis jmdavisProg at gmx.com
Mon Aug 29 14:18:31 PDT 2011


On Monday, August 29, 2011 15:18 Mariusz Gliwiński wrote:
> 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.

This seems to compile just fine:

interface Interface
{
 Interface method();
}
class Class : Interface
{
 Class method() {return new Class;}
}

The problem is the override keyword. _No_ overriding is going on. _That's_ why 
it's complaining.

- Jonathan M Davis


More information about the Digitalmars-d mailing list