Inheritance and Lookup
4: doesNotUnderstand: aMessage
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
Goal
- A hook message is sent when the lookup fails
- Classes can customize the reaction to this failure
Message Sending
Sending a message is a two-step process:
- look up the method matching the message
- execute this method on the receiver
When No Method is Found
- if no method is found in the hierarchy,
doesNotUnderstand:
is sent to the receiver
- the initial message is passed as parameter
When No Method is Found
Step by Step...
node1 coucou: #stef
coucou:
looked up in Node
- not defined in
Node
-> continues in Object
- not defined in
Object
-> send doesNotUnderstand:
to node1
doesNotUnderstand:
looked up in Node
- not defined in
Node
-> continues in Object
doesNotUnderstand:
is found and executed
doesNotUnderstand: is a Message
doesNotUnderstand:
is a message
- any class can implement the corresponding method
- used for automatic delegation, proxy, distribution
doesNotUnderstand: and the Debugger
When no class redefines doesNotUnderstand:
doesNotUnderstand:
in Object
is executed
- this method raises a
MessageNotUnderstood
exception
- when not handled, this exception opens a debugger
Catching MessageNotUnderstood Error
MessageNotUnderstood
is just an exception, code can handle it:
What You Should Know
- The lookup sends
doesNotUnderstand:
when it can not find a method
- Each class can implement this method
- The default implementation of
doesNotUnderstand:
raises an exception that can be handled
/