Non-Virtual Interface and Interface Implementation

Matthias Frei matfrei at ethz.ch
Sun Nov 13 04:23:12 PST 2011


On 11/11/2011 05:38 PM, Trass3r wrote:
> Am 11.11.2011, 17:16 Uhr, schrieb Matthias Frei <matfrei at ethz.ch>:
>
>> Hi,
>>
>> i had the seemingly innocent idea to use the "NVI idiom" in the
>> following way:
>>
>> interface Foo {
>> void foo();
>> }
>>
>> interface FooFoo : Foo {
>> final void foo() {
>> // do something with bar()
>> }
>> void bar();
>> }
>>
>> class Bar : FooFoo {
>> void bar() {
>> // do something
>> }
>> }
>>
>> My idea was to check some default cases etc. in the FooFoo.foo() and
>> call the bar() implementation from there.
>>
>> However it turned out that is is not possible:
>> Error: class test.Bar interface function FooFoo.foo isn't implemented
>>
>> This is very weird, because of course Bar cannot implement foo() as it
>> is declared final in FooFoo.
>>
>> Is there some particular reason that this does not work?
>>
>> Matthias
>
> Probably a bug. final interface methods are relatively new, I guess
> nobody has tested interfaces inheriting interfaces yet.
> It also doesn't error on bar missing override.

Ok, thanks. Still cool that it should work ;)


More information about the Digitalmars-d mailing list