RosettaCodeData/Task/Delegates/D/delegates-1.d
2023-07-01 13:44:08 -04:00

24 lines
528 B
D

class Delegator {
string delegate() hasDelegate;
string operation() {
if (hasDelegate is null)
return "Default implementation";
return hasDelegate();
}
typeof(this) setDg(string delegate() dg) {
hasDelegate = dg;
return this;
}
}
void main() {
import std.stdio;
auto dr = new Delegator;
string delegate() thing = () => "Delegate implementation";
writeln(dr.operation());
writeln(dr.operation());
writeln(dr.setDg(thing).operation());
}