overridding without subclassing examples

Michael van der Gulik mikevdg at gmail.com
Wed Sep 19 05:14:24 UTC 2007


On 9/19/07, Brad Fuller <bradallenfuller at yahoo.com> wrote:
>
> Is there a way to override an instance method w/o subclassing?
> For instance, class Morph has a method that returns true, but I want the
> that
> method to return false when instancing some types of Morphs and others
> not.
> (there is no setter/getter for this method.) Is there a way to do that w/o
> adding a setter/getter to Morph or subclassing the different Morphs?
>
>
Er... my immediate suspicion is that you'd want to take a step back and ask
yourself /why/ you're doing this.

There is some black magic you can do to achieve this hackery, but beware,
this is very powerful magic and many images have been killed in its making.

Before you run your test, save your image. Do not save your image after
running your test; instead, trash the image and start it up again from your
save.

Install this: http://www.squeaksource.com/DPON/MessageCapture-mvdg.9.mcz,
try to understand it and let me know if you can't understand my comments.

Set up message capture on the Morph you want. Implement a message handler to
do the logic you need for one set of clients and give them the
MessageCapture object. Give the original Morph to the other objects.

Good luck! And remember - don't save your image after you run this until
you're sure it works. The debugger and inspector will crash the image if you
try to use them.

Another way would be to inspect thisContext to see who the sender is and do
conditional logic that way.

Regards,
Gulik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070919/24714e1f/attachment.htm


More information about the Squeak-dev mailing list