Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Delegates/Dart/delegates.dart
Normal file
29
Task/Delegates/Dart/delegates.dart
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
class Delegator {
|
||||
var delegate;
|
||||
|
||||
String operation() {
|
||||
if (delegate == null)
|
||||
return "default implementation";
|
||||
else
|
||||
return delegate.thing();
|
||||
}
|
||||
}
|
||||
|
||||
class Delegate {
|
||||
String thing() => "delegate implementation";
|
||||
}
|
||||
|
||||
main() {
|
||||
// Without a delegate:
|
||||
Delegator a = new Delegator();
|
||||
Expect.equals("default implementation",a.operation());
|
||||
|
||||
// any object doesn't work unless we can check for existing methods
|
||||
// a.delegate=new Object();
|
||||
// Expect.equals("default implementation",a.operation());
|
||||
|
||||
// With a delegate:
|
||||
Delegate d = new Delegate();
|
||||
a.delegate = d;
|
||||
Expect.equals("delegate implementation",a.operation());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue