patching base classes

Scott Wallace Scott.Wallace at disney.com
Thu Nov 18 06:51:37 UTC 1999


Juan,

I think that Ian intended us to understand that, for example, if you 
had a class "Foo" and wanted "isFoo" to answer whether or not an 
object is a Foo, then Foo itself would be expected to implement 
#isFoo explicitly, as follows:

isFoo
      "Answer whether the receiver is a Foo."
      ^ true

Ian's Object.doesNotUnderstand code would then see to it that any 
non-Foo would answer "false" to the #isFoo query, without anyone 
needing to put an explicit and intrusive #isFoo method into Object.

The explicit presence of an #isFoo implementation in class Foo would, 
besides giving a fast positive response, allow a user browsing 
implementors of it to understand what's going on (rather than being 
baffled by finding no implementors of a message that is plainly sent.)

   -- Scott


At 1:21 AM -0500 11/18/99, Juan Manuel Vuletich wrote:
>I guess it was a joke, the method always answered false...


Ian's original message:

Date: Wed, 17 Nov 1999 20:03:29 +0100 (MET)
From: Ian Piumarta <Ian.Piumarta at inria.fr>
Subject: Re: patching base classes

> Populating Object with "is...." messages seems... just... wrong and
> unscalable.


Object>>doesNotUnderstand: aMessage
	 "Handle the fact that there was an attempt to send the given 
message to the receiver but the receiver does not understand this 
message (typically sent from the machine when a message is sent to 
the receiver and no method is defined for that selector)."
	"Testing: (3 activeProcess)"

	(Preferences autoAccessors and: [self 
tryToDefineVariableAccess: aMessage])
		ifTrue: [^ aMessage sentTo: self].
	(Preferences autoDeclineMembership
		and: [(aMessage selector beginsWith: 'is')
		and: [Symbol
				hasInterned: (aMessage selector 
copyFrom: 3 to: aMessage selector size)
				ifTrue: [:sym | (Smalltalk 
includesKey: sym) ifTrue: [^false]]]])
		ifTrue: [^ false].
	MessageNotUnderstood new message: aMessage;
		signal.
	^aMessage sentTo: self

"42 isFrob"
"42 isInterpreter"
"Preferences enable: autoDeclineMembership"
"42 isFrob"
"42 isInterpreter"

Happy scaling!

Ian
     ;-)





More information about the Squeak-dev mailing list