Instance-specific behavior

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Instance-specific behavior

Sean P. DeNigris
Administrator
What would be the best way (as an experiment) to change the behavior of just one instance. For example, say:
  SpecialMorph>>#color
    ^ Color blue.
but (the effect of)
  aSpecialMorph>>#color
    ^ owner color.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Instance-specific behavior

Alejandro Infante
Proxy maybe? I remember an example in Pharo by Example Book chapter 13 or 14.

So the main idea would be:
Create MyProxy, subclass of ProtoObject and with an instance variable.

MyProxy>>initialize
  morph := self.

Override doesNotUnderstand to dispatch the message to the other object.
Also implement your custom behavior in the MyProxy.

Then use #become: to install the proxy. (The one that swaps all the references)

Cheers,
Alejandro 



2014-02-04 Sean P. DeNigris <[hidden email]>:
What would be the best way (as an experiment) to change the behavior of just
one instance. For example, say:
  SpecialMorph>>#color
    ^ Color blue.
but (the effect of)
  aSpecialMorph>>#color
    ^ owner color.



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Instance-specific-behavior-tp4741502.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Instance-specific behavior

pharo4Stef@free.fr
In reply to this post by Sean P. DeNigris
Have a look at my old JOOP paper on message passing control
        - you can have anonymous subclasses
        where you compile some methods+ changeclass.

Stef
On 04 Feb 2014, at 19:30, Sean P. DeNigris <[hidden email]> wrote:

> What would be the best way (as an experiment) to change the behavior of just
> one instance. For example, say:
>  SpecialMorph>>#color
>    ^ Color blue.
> but (the effect of)
>  aSpecialMorph>>#color
>    ^ owner color.
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/Instance-specific-behavior-tp4741502.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Instance-specific behavior

Sean P. DeNigris
Administrator
Pharo4Stef wrote
Have a look at my old JOOP paper on message passing control
Found it - thanks :)
Cheers,
Sean