LazyInterface (simplified Boost.Interfaces)

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Sep 22 06:34:19 PDT 2010


On 9/21/10 14:36 CDT, kenji hara wrote:
> Hi.
>
> I heard Boost.Interfaces recently. Then, it implemented by D.
> http://github.com/9rnsr/scrap/blob/master/interfaces/interfaces.d
>
> How about you?

Hi Kenji,


Looking very interesting. One thing I'd change would be the interface 
definition. Ideally the client code would look like this:

static class A
{
   int draw(){ return 10; }
}

static class B : A
{
   int draw(){ return 20; }
}

interface Drawable
{
   int draw();
};

unittest
{
   Drawable d = adaptTo!Drawable(new A);
   assert(d.draw() == 10);
   d = adaptTo!Drawable(new B);
   assert(d.draw() == 20);
}

adaptTo would rely on introspection and code generation to define an 
implementation of Drawable that forwards calls to an object.


Andrei


More information about the Digitalmars-d mailing list