digitalmars.D - Non-Virtual Interface and Interface Implementation
- Matthias Frei (25/25) Nov 11 2011 Hi,
- Trass3r (4/29) Nov 11 2011 Probably a bug. final interface methods are relatively new, I guess nobo...
- Andrej Mitrovic (1/1) Nov 11 2011 I thought interfaces can't have function bodies?
- Timon Gehr (4/5) Nov 11 2011 They can have final functions with bodies in it, Andrei calls it the
- Marco Leise (3/41) Nov 11 2011 Wow, this works? I was just recently thinking about it. I don't think ma...
- Jonathan M Davis (5/6) Nov 11 2011 They can for final functions (which is unique to D, I believe). There ar...
- Matthias Frei (2/40) Nov 13 2011 Ok, thanks. Still cool that it should work ;)
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
Nov 11 2011
Am 11.11.2011, 17:16 Uhr, schrieb Matthias Frei <matfrei 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? MatthiasProbably 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.
Nov 11 2011
I thought interfaces can't have function bodies?
Nov 11 2011
On 11/11/2011 07:28 PM, Andrej Mitrovic wrote:I thought interfaces can't have function bodies?They can have final functions with bodies in it, Andrei calls it the 'Non-Virtual Interface Idiom'. It is described in TDPL starting from page 213.
Nov 11 2011
Am 11.11.2011, 17:38 Uhr, schrieb Trass3r <un known.com>:Am 11.11.2011, 17:16 Uhr, schrieb Matthias Frei <matfrei ethz.ch>:Wow, this works? I was just recently thinking about it. I don't think many languages allow implementations in interfaces and I appreciate it.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? MatthiasProbably 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.
Nov 11 2011
On Friday, November 11, 2011 10:28 Andrej Mitrovic wrote:I thought interfaces can't have function bodies?They can for final functions (which is unique to D, I believe). There are a few things about interfaces that are unique to D, but I'd have to go reread the relevant section in TDPL to remember all of the details. - Jonathan M Davis
Nov 11 2011
On 11/11/2011 05:38 PM, Trass3r wrote:Am 11.11.2011, 17:16 Uhr, schrieb Matthias Frei <matfrei ethz.ch>:Ok, thanks. Still cool that it should work ;)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? MatthiasProbably 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.
Nov 13 2011