Differing implementations for a function in two interfaces

Chris Nicholson-Sauls ibisbasenji at gmail.com
Sat Apr 15 03:12:22 PDT 2006


Lionello Lunesu wrote:
> #class Command : IResult, IResultRow {    // handle wrapper
...
> #    int IResult.opApply( int delegate(inout IResultRow) dg );
...
> #    int IResultRow.opApply( int delegate(inout IResultField) dg );
> #}

I actually rather like this syntax.  When I first started reading your post, this was 
precisely what I thought of as a possible general purpose solution.  The difficulty I see 
is in how to select which to use at call-time.  In your case, I see you use a simple 
`cast(Interface) object` to do so, which seems fair enough... but might there be another 
way to do the selection in simpler expressions?

# class Foo : IA, IB { ... } // IA and IB declare: int get();
#
# Foo obj = new Foo;
#
# // call IA.get()... ew
# (cast(IA) obj).get();
#
# // call IB.get()... eh
# obj.get at IB();
# // or
# obj at IB.get();
#
# // call IA.get()... erm
# obj.IA::get();

Just thinking.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d-learn mailing list