Delegates: Difference between revisions
Content deleted Content added
Io: added output |
|||
Line 724: | Line 724: | ||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 3.x : |
|||
<lang elena>#import system. |
|||
#import system'routines. |
<lang elena>#import system'routines. |
||
dispatchable(delegate) class Operable |
|||
{ |
{ |
||
⚫ | |||
#method cast:verb &to:target |
|||
= target::verb eval &delegate:$self. |
|||
⚫ | |||
= "delegate implementation". |
= "delegate implementation". |
||
} |
} |
||
class Delegator |
|||
{ |
{ |
||
object theDelegate. |
|||
constructor new |
|||
[ |
[ |
||
theDelegate := nil. |
theDelegate := nil. |
||
] |
] |
||
set &Delegate:obj |
|||
[ |
[ |
||
($nil == obj) |
($nil == obj) |
||
Line 751: | Line 748: | ||
! [ theDelegate := obj. ]. |
! [ theDelegate := obj. ]. |
||
] |
] |
||
operate |
|||
= theDelegate cast:%eval &to: |
= theDelegate cast:%eval &to: |
||
{ |
{ |
||
delegate : o = o operate. |
delegate : o = o operate. |
||
! |
! o = "default implementation". |
||
}. |
}. |
||
} |
} |
||
program = |
|||
[ |
[ |
||
var delegator := Delegator new. |
|||
($nil, Object new, Operable new) run &each: o |
($nil, Object new, Operable new) run &each: o |
||
[ |
[ |
||
delegator set &Delegate:o. |
delegator set &Delegate:o. |
||
console writeLine:(delegator operate). |
console writeLine:(delegator operate). |
||
]. |
]. |