Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
41
Task/Delegates/Wren/delegates.wren
Normal file
41
Task/Delegates/Wren/delegates.wren
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
class Thingable {
|
||||
thing { }
|
||||
}
|
||||
|
||||
// Delegate that doesn't implement Thingable
|
||||
class Delegate {
|
||||
construct new() { }
|
||||
}
|
||||
|
||||
// Delegate that implements Thingable
|
||||
class Delegate2 is Thingable {
|
||||
construct new() { }
|
||||
|
||||
thing { "delegate implementation" }
|
||||
}
|
||||
|
||||
class Delegator {
|
||||
construct new() {
|
||||
_delegate = null
|
||||
}
|
||||
|
||||
delegate { _delegate }
|
||||
delegate=(d) { _delegate = d }
|
||||
|
||||
operation {
|
||||
if (!_delegate || !(_delegate is Thingable)) return "default implementation"
|
||||
return _delegate.thing
|
||||
}
|
||||
}
|
||||
|
||||
// without a delegate
|
||||
var d = Delegator.new()
|
||||
System.print(d.operation)
|
||||
|
||||
// with a delegate that doesn't implement Thingable
|
||||
d.delegate = Delegate.new()
|
||||
System.print(d.operation)
|
||||
|
||||
// with a delegate that does implement Thingable
|
||||
d.delegate = Delegate2.new()
|
||||
System.print(d.operation)
|
||||
Loading…
Add table
Add a link
Reference in a new issue