[Issue 16318] inherit from interface via abstract class

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Aug 12 00:54:20 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16318

--- Comment #2 from Lodovico Giaretta <lodovico at giaretart.net> ---
(In reply to b2.temp from comment #1)
> Your request is not valid because it already works. You forget that an
> interface method has to be implemented at least once before being
> overridden, otherwise what do you override ? An interface method is not like
> an abstract method and the error message couldn't be more accurate.

Sorry, I don't understand your reasoning, so I'd love if you could answer the
following points. Thank you in advance for spending your time on this.

If I inherit directly from an interface, I can override:

==================
interface IFoo { void foo(); }

class FooImpl: IFoo { override void foo(); } // override here is fine
==================

It seems counterintuitive that you can't do this transitively:

==================
interface IFoo { void foo(); }

abstract class AFoo: IFoo {}

class FooImpl: AFoo { override void foo(); } // override here does not work
==================

It is true that it works if I remove "override", but this makes it unclear that
FooImpl.foo overrides IFoo.foo. When I encountered this, it made me think that
FooImpl.foo was just hiding IFoo.foo because of some signature error I did.

Also, I have an interface with *lots* of methods, and an abstract base class
that only implements a tiny portion of them. Having to explicitly enumerate the
methods that I'm not implementing bloats my code.

--


More information about the Digitalmars-d-bugs mailing list