Skip to content

Delegation of Messages

When an object receives a message, it attempts to "understand" the message. The message will be understood if the object's class or any of its superclasses understands it. If the object does not understand the message, the message will be sent on to the receiving object’s parent object. The parent object attempts to resolve the message in the same way, by checking its own class hierarchy. If the parent does not understand the message, it will send the message on to its parent. This is repeated until either the message is resolved or the desktop object receives the message (and fails to understand it), resulting in an error.

BMPlng02.gif

The process of sending a message on to the parent object is called delegation.

Assume that Objects E and C both understand the message jump. Assume that only Object A understands the message hop. If we send the message jump to either Object C or E, the message will be understood by that object. In other words, the class hierarchy that Objects E and C are based on was able to resolve the message.

If we send the message hop to Object E, that object will not understand the message. The message will get resolved through delegation. Object E would delegate the message to Object D, which would then delegate the message to Object A.

Object E did not resolve the message; Object A did. It is as if the message were sent directly to Object A. Finally, note that sending the message jump to Object B (or D) will result in an error. Jump will get sent to B, delegated to A, delegated to the desktop, where an error will be reported. If you understand these examples, you understand delegation of messages.

There are three types of messages: send, get, and set. All three of these message types perform message delegation. The Get message type supports an additional expression style syntax which can be used to send messages. For example, these two lines of code are functionally the same:

get function_name to variable
move (function_name(self)) to variable

Message delegation is supported and is the same for both formats. We recommend that you use the get syntax with function methods.

Next Topic

Delegation of Access Methods