Non-Virtual Interface and Interface Implementation

Matthias Frei matfrei at ethz.ch
Fri Nov 11 08:16:11 PST 2011


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


More information about the Digitalmars-d mailing list