Decouple package modules with package interfaces

simendsjo simendsjo at gmail.com
Mon Sep 23 23:54:42 PDT 2013


I just came across a problem where I either has a cyclic 
dependency, pass around three delegates, implement an interface 
or somehow hack some communication between two modules.

A simple way would be to add an interface, but interfaces require 
implementations to be public. The methods should be package 
protected though.

It would have been nice if the implementation for an interface 
wouldn't have to be more visible than the interface itself.

If an interface is "package", it cannot escape that package, so 
why would the implementation required to be public? The same goes 
for "private".

Should I add an enhancement request for this, or does it have 
problems I'm not seeing?

---

module b;

package interface I {
     void doit();
}

void f(I i) { i.doit(); }

---

module a;
import b;

class C : I {  // Error: class a.C interface function 'void 
doit()' is not implemented
     package void doit() {}
}

void main() {
     auto c = new C;
     f(c);
}


More information about the Digitalmars-d-learn mailing list