Order of interface implementations affects code

Andrej Mitrovic none at none.com
Thu Oct 14 10:14:25 PDT 2010


Should the order in which you implement interfaces have an effect in your code? It seems to be that way when you have two functions with the same name in the different interfaces. Here's an example:

import std.stdio : writeln;

interface Foo
{
    final void run() { writeln("foo"); } 
}

interface Bar
{
    final void run() { writeln("bar"); } 
}

class One : Foo, Bar
{
}

class Two : Bar, Foo
{
}

void main()
{
    with (new One)
    {
        run();  // writes foo
    }

    with (new Two)
    {
        run();  // writes bar
    }
}

Bug? Or legitimate working code?


More information about the Digitalmars-d-learn mailing list