Delegates: Difference between revisions

Line 1,118:
return 0;
}</lang>
 
 
=={{header|Oforth}}==
<lang Oforth>Object Class new: Delegate1
 
Object Class new: Delegate2
Delegate2 method: thing { "Delegate implementation" println }
 
Object Class new: Delegator(delegate)
Delegator method: initialize { := delegate }
 
Delegator method: thing
{
@delegate ifNotNull: [
@delegate respondTo(#thing) ifTrue: [ @delegate thing return ]
]
"Default implementation" println
}</lang>
Usage :
 
<lang Oforth>Delegator new(null) thing
Default implementation
 
Delegator new(Delegate1 new) thing
Default implementation
 
Delegator new(Delegate2 new) thing
Delegate implementation</lang>
 
=={{header|ooRexx}}==
1,015

edits