Delegates: Difference between revisions

Content deleted Content added
Line 721: Line 721:
> delegator.operation()
> delegator.operation()
# value: "default implementation"</lang>
# value: "default implementation"</lang>


=={{header|Elena}}==
<lang elena>#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).
].
].</lang>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==