actionscript-3: refactor interface inheritance to get rid of ambiguous reference error

Posted by maxmc on Stack Overflow See other posts from Stack Overflow or by maxmc
Published on 2010-05-15T16:29:01Z Indexed on 2010/05/15 16:34 UTC
Read the original article Hit count: 313

hi!

imagine there are two interfaces arranged via composite pattern, one of them has a dispose method among other methods:

interface IComponent extends ILeaf {
    ...
    function dispose() : void;
}

interface ILeaf {
    ...
}

some implementations have some more things in common (say an id) so there are two more interfaces:

interface ICommonLeaf extends ILeaf {
    function get id() : String;
}

interface ICommonComponent extends ICommonLeaf, IComponent {
}

so far so good. but there is another interface which also has a dispose method:

interface ISomething {
    ...
    function dispose() : void;
}

and ISomething is inherited by ICommonLeaf:

interface ICommonLeaf extends ILeaf, ISomething {
    function get id() : String;
}

As soon as the dispose method is invoked on an instance which implements the ICommonComponent interface, the compiler fails with an ambiguous reference error because ISomething has a method called dispose and ILeaf also has a dispose method, both living in different interfaces (IComponent, ISomething) within the inheritace tree of ICommonComponent.

I wonder how to deal with the situation if

  • the IComponent, the ILeaf and the ISomething can't change.
  • the composite structure must also work for for the ICommonLeaf & ICommonComponent
  • implementations and the ICommonLeaf & ICommonComponent must conform to the ISomething type.

this might be an actionscript-3 specific issue. i haven't tested how other languages (for instance java) handle stuff like this.

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about best-practices