LazyInterface (simplified Boost.Interfaces)

kenji hara k.hara.pg at gmail.com
Thu Sep 23 06:09:37 PDT 2010


I implemented adaptTo .

http://github.com/9rnsr/scrap/blob/master/interfaces/interfaces.d

Kenji Hara

2010/9/22 kenji hara <k.hara.pg at gmail.com>:
> Thanks for your advise, Andrei.
>
> I will try to implement adaptTo!T .
>
> Kenji Hara
>
> 2010/9/22 Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:
>> 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