DoesNotUnderstand: a Precious Hook
Damien Cassou, Stéphane Ducasse and Luc Fabresse
http://stephane.ducasse.free.fr
When No Method is Found
doesNotUnderstand: is a Message
doesNotUnderstand:
is a message
- Every class can customize this hook
- Important hook for automatic delegation, distributed programming and many other usages
Example 1: Delegation
Redirect unknown messages to another object (a target)
Example 1: Delegation
- Pay attention it blurs code understandability
- Only tools and specific parts should use such tricks
Example 2: A LoggingProxy
Basic idea:
- Create a 'minimal' object raising error to most messages
- Customize its
doesNotUnderstand:
method
- Swap an object and the proxy
Implementing LoggingProxy
Customize doesNotUnderstand:
Message Behavior
Some Limits of such Minimal Objects
- Messages sent by the object to itself are not trapped!
- Class cannot be swapped
- What to do with messages that are understood by both the minimalObject and its subject?
Another Application
Scaffolding patterns: Generate code on the fly based of patterns
Conclusion
Minimal Objects
- Basis for proxies
- Multiple usages (distribution, object loading, spying)
doesNotUnderstand:
- Powerful hook
- Only to be used when needed
/