2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
48
Task/Delegates/Elena/delegates.elena
Normal file
48
Task/Delegates/Elena/delegates.elena
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#import system.
|
||||
#import system'routines.
|
||||
|
||||
#class Operable
|
||||
{
|
||||
#method cast:verb &to:target
|
||||
= target::verb eval &delegate:$self.
|
||||
|
||||
#method operate
|
||||
= "delegate implementation".
|
||||
}
|
||||
|
||||
#class Delegator
|
||||
{
|
||||
#field theDelegate.
|
||||
|
||||
#constructor new
|
||||
[
|
||||
theDelegate := nil.
|
||||
]
|
||||
|
||||
#method set &Delegate:obj
|
||||
[
|
||||
($nil == obj)
|
||||
? [ theDelegate := nil. ]
|
||||
! [ theDelegate := obj. ].
|
||||
]
|
||||
|
||||
#method operate
|
||||
= theDelegate cast:%eval &to:
|
||||
{
|
||||
delegate : o = o operate.
|
||||
|
||||
! : o = "default implementation".
|
||||
}.
|
||||
}
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var delegator := Delegator new.
|
||||
|
||||
($nil, Object new, Operable new) run &each: o
|
||||
[
|
||||
delegator set &Delegate:o.
|
||||
|
||||
console writeLine:(delegator operate).
|
||||
].
|
||||
].
|
||||
22
Task/Delegates/Io/delegates.io
Normal file
22
Task/Delegates/Io/delegates.io
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Delegator := Object clone do(
|
||||
delegate ::= nil
|
||||
operation := method(
|
||||
if((delegate != nil) and (delegate hasSlot("thing")),
|
||||
delegate thing,
|
||||
"default implementation"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Delegate := Object clone do(
|
||||
thing := method("delegate implementation")
|
||||
)
|
||||
|
||||
a := clone Delegator
|
||||
a operation println
|
||||
|
||||
a setDelegate("A delegate may be any object")
|
||||
a operation println
|
||||
|
||||
a setDelegate(Delegate clone)
|
||||
a operation println
|
||||
Loading…
Add table
Add a link
Reference in a new issue