Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Delegates/E/delegates.e
Normal file
34
Task/Delegates/E/delegates.e
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
def makeDelegator {
|
||||
/** construct without an explicit delegate */
|
||||
to run() {
|
||||
return makeDelegator(null)
|
||||
}
|
||||
|
||||
/** construct with a delegate */
|
||||
to run(delegateO) { # suffix because "delegate" is a reserved keyword
|
||||
def delegator {
|
||||
to operation() {
|
||||
return if (delegateO.__respondsTo("thing", 0)) {
|
||||
delegateO.thing()
|
||||
} else {
|
||||
"default implementation"
|
||||
}
|
||||
}
|
||||
}
|
||||
return delegator
|
||||
}
|
||||
}
|
||||
|
||||
? def delegator := makeDelegator()
|
||||
> delegator.operation()
|
||||
# value: "default implementation"
|
||||
|
||||
? def delegator := makeDelegator(def doesNotImplement {})
|
||||
> delegator.operation()
|
||||
# value: "default implementation"
|
||||
|
||||
? def delegator := makeDelegator(def doesImplement {
|
||||
> to thing() { return "delegate implementation" }
|
||||
> })
|
||||
> delegator.operation()
|
||||
# value: "default implementation"
|
||||
Loading…
Add table
Add a link
Reference in a new issue