Non-Virtual Interface and Interface Implementation

Marco Leise Marco.Leise at gmx.de
Fri Nov 11 10:30:51 PST 2011


Am 11.11.2011, 17:38 Uhr, schrieb Trass3r <un at known.com>:

> 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.

Wow, this works? I was just recently thinking about it. I don't think many  
languages allow implementations in interfaces and I appreciate it.


More information about the Digitalmars-d mailing list