doesNotUnderstand: is a messageRedirect unknown messages to another object (a target)
Object subclass: #Delegating
instanceVariableNames: 'target'Delegating >> doesNotUnderstand: aMessage
^ aMessage sendTo: self targetBasic idea:
doesNotUnderstand: methodProtoObject subclass: #LoggingProxy
instanceVariableNames: 'subject invocationCount'
classVariableNames: ''
package: 'LoggingProxy'LoggingProxy >> initialize
invocationCount := 0.
subject := self
"will be swapped by become:"LoggingProxy >> doesNotUnderstand: aMessage
Transcript show: 'performing ', aMessage printString; cr.
invocationCount := invocationCount + 1.
^ aMessage sendTo: subjectMessage >> sendTo: receiver
^ receiver perform: selector withArguments: args| point |
point := 1@2.
LoggingProxy new become: point.
self assert: point invocationCount = 0.
self assert: point x + point y = 3.
self assert: point + (3@4) = (4@6).
self assert: point invocationCount = 3.
Scaffolding patterns: Generate code on the fly based of patterns
DynamicAccessors >> doesNotUnderstand: aMessage
| messageName |
messageName := aMessage selector asString.
(self class instVarNames includes: messageName)
ifTrue: [self class compile:
messageName , String cr , ' ^ ' , messageName.
^ aMessage sendTo: self].
super doesNotUnderstand: aMessageMinimal Objects
doesNotUnderstand:
/