Delegates: Difference between revisions
Content deleted Content added
Add NGS implementation |
added Io entry |
||
Line 918: | Line 918: | ||
fmt.Println(a.operation()) // prints "delegate implementation" |
fmt.Println(a.operation()) // prints "delegate implementation" |
||
}</lang> |
}</lang> |
||
=={{header|Io}}== |
|||
{{trans|Python}} |
|||
<lang Io>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</lang> |
|||
=={{header|J}}== |
=={{header|J}}== |