Default method implementations in interfaces?

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 23 08:08:29 PDT 2015


On Friday, 23 October 2015 at 14:58:43 UTC, pineapple wrote:
> Is it possible to have default method implementations in 
> interfaces à la Java in D? Or some equivalent that allows 
> multiple inheritance without a bunch of identical copypasted 
> method bodies?

Use a mixin template together with your interface. Here's an 
example from my book:

http://arsdnet.net/dcode/book/chapter_06/09/multiple_inheritance.d

https://www.packtpub.com/application-development/d-cookbook

Notice that there's default implementations for each interface, 
you mix them in to get it all and can override individual names 
in the class too.


More information about the Digitalmars-d-learn mailing list