Iyael
Iyael

Reputation: 107

Message forwarding with doesNotUnderstand in Smalltalk

I had a query about redefining the message doesNotUnderstand: in smalltalk. What I want to do is to forward all the messages received by an object that are not understood, to another object that it has in its knowledge. My problem comes from the fact that both objects (both the receiver and the one that forwards) have the same protocol inherited by the super class and when the message is not understood by the specific protocol of the object but if it is understood by the inherited protocol, it executes the message inherited and not the doesNotUnderstand: (so the message is not forwarded and the super class message is invoked).

I really appreciate the help, regards!

Upvotes: 4

Views: 435

Answers (1)

James Foster
James Foster

Reputation: 2210

As I understand it, you have a situation in which you want to forward a message but it is understood by the one that forwards (we call that a proxy object) so doesNotUnderstand: is not being invoked in the proxy.

You have two possible solutions. First (and in general), a proxy object should inherit from ProtoObject so as to avoid inheriting any default behavior. But if this is not a true proxy object (that passes along essentially everything), then you need to override the messages that should be forwarded and call doesNotUnderstand: (or your forwarding code) directly.

Upvotes: 8

Related Questions