The Non-Virtual Interface idiom in D

"Jérôme M. Berger" jeberger at free.fr
Wed Sep 30 11:43:43 PDT 2009


Jeremie Pelletier wrote:
> Jérôme M. Berger wrote:
>> Michel Fortin wrote:
>>> I fully support having a way to specify a default implementation for 
>>> a function in an interface. It might get handy for a few things (like 
>>> implementing the delegate pattern you see everywhere in Cocoa). But 
>>> it's a bad replacement for contracts.
>>>
>>     Then what's the difference between an interface and an abstract 
>> class? I thought that the whole point of interfaces was that you 
>> couldn't have implementations of the methods so that you had no 
>> problem choosing an implementation when inheriting from multiple 
>> interfaces.
>>
>>         Jerome
> 
> The interface supports multiple inheritance since it doesn't add to the 
> vtable of the class using it,

	?? The interface adds as much (or as little) to the vtable as 
another class would. The reason why interfaces support multiple 
inheritance is that since the interface does not contain the code 
for any of its methods, there is never any doubt which method should 
be called even if several ancestors have methods with the same 
signature. Once you add code to the interface you loose that advantage.

> and its code would be implemented on the 
> classes implementing the interface, not overridden by subclasses.

	I don't see how that's different from standard class inheritance. 
After all there is nothing that forces you to override methods in 
subclasses if they already have an implementation in the parent 
class either.

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20090930/91eb7207/attachment.pgp>


More information about the Digitalmars-d mailing list