Implicit Interface Deduction

Faux Amis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 16 08:19:27 PST 2015


On Mon 14/12/2015 00:27, Ali Çehreli wrote:
> On 12/13/2015 02:09 PM, Faux Amis wrote:
>> interface IA {}
>> interface IB {}
>> interface IC {}
>> interface IAB : IA, IB {}
>> interface IBC : IB, IC {}
>>
>> class C : IA, IB, IC {}
>> // Defining C as : IAB, IBC
>> // is not really scalable ;)
>>
>
> It is not automatic at least because of implementation details: The
> compiler should not generate a vtbl for every possible interface.
>
> Is it acceptable to add IAB and IBC to C? If so, this works:
>
> import std.stdio;
>
> class C : IA, IB, IC, IAB, IBC {
>      void a() { writeln(__FUNCTION__); }
>      void b() { writeln(__FUNCTION__); }
>      void c() { writeln(__FUNCTION__); }
> }
>
> Ali
>
So, you would just add the combined interfaces to the definition.
Maybe with some nice separation this would be acceptable.

class C : IA, IB, IC,
	IAB, IBC // implicit
{
	// body
}

Enforcement would be difficult.
Forgetting IB, for instance, will still compile.


More information about the Digitalmars-d-learn mailing list