Automatic Interface Implementation
JS
js.mdnq at gmail.com
Fri Jul 5 10:53:10 PDT 2013
I ripped and hacked up some code from typecons that allows one to
implement an interface automatically by redirecting it to a
variable implementing the interface.
http://dpaste.dzfl.pl/209e260b
To see the effectiveness of the code, notice that very little, if
any, boilerplate code needs to be used to implement such a
pattern:
interface A
{
void foo();
void foo2();
int bar(int x);
void bar(string c);
}
// Dummy class for A
class AA : A { void foo() { writeln("AA.foo"); } void foo2() {
writeln("AA.foo2"); } int bar(int x) { writeln("AA.bar(int)");
return 0; } void bar(string c) { writeln("AA.bar(string)"); } }
class B : A
{
A a;
void foo2() { writeln("B.foo2"); }
mixin implementComposite!a;
}
I'm not sure how this code holds up though, it's possible
templated classes and other more complex implementations may
cause some problems....
It will probably do fine for what I need it to do but maybe
someone else will find it useful or can make it better...
More information about the Digitalmars-d
mailing list