On Wednesday, 30 September 2015 at 19:17:41 UTC, Steven
Schveighoffer wrote:
On 9/30/15 2:12 PM, Jan Johansson wrote:
[...]
There is no reason to use interfaces here, you can separate
declaration from implementation without them:
test.di:
module test;
class MyTest {
void Write(string message);
}
test.d:
module test;
class MyTest {
void Write(string message) {
writeln(message);
}
}
main.d:
import test; // will work even if only test.di is available
import std.stdio;
void main() {
auto p = new MyTest;
p.Write("Hello, World!");
}
Interfaces are only necessary when you are unsure what concrete
type you need until runtime.
-Steve
Thanks Steve,
Your last statement is exactly what I want to do! Using contract
based design, and factories to instantiate types that implements
the interface.
//Jan