Delegates: Difference between revisions
Content added Content deleted
Line 2,421: | Line 2,421: | ||
NonDelegate: default implementation |
NonDelegate: default implementation |
||
Delegate: delegate implementation |
Delegate: delegate implementation |
||
=={{header|Smalltalk}}== |
|||
{{works with|Smalltalk/X}} |
|||
Definition of the thingy: |
|||
<lang smalltalk> |
|||
Object |
|||
subclass:#Thingy |
|||
instanceVariableNames:'' |
|||
classVariableNames:'' |
|||
poolDictionaries:'' |
|||
thing |
|||
^ 'thingy implementation' |
|||
</lang> |
|||
Definition of the delegator: |
|||
<lang smalltalk> |
|||
Object |
|||
subclass:#Delegator |
|||
instanceVariableNames:'delegate' |
|||
classVariableNames:'' |
|||
poolDictionaries:''. |
|||
delegate:something |
|||
delegate := something |
|||
operation |
|||
^ delegate |
|||
perform:#thing |
|||
ifNotUnderstood:'default implementation'. |
|||
</lang> |
|||
Sample use: |
|||
<lang smalltalk> |
|||
|d| |
|||
d := Delegator new. |
|||
d operation. |
|||
-> 'default implementation' |
|||
d delegate:(Thingy new). |
|||
d operation. |
|||
-> 'thingy implementation' |
|||
</lang> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |