[Newbies] dependency mechanism
Chris Kassopulo
cpulo at earthlink.net
Tue May 30 18:11:22 UTC 2006
Greetings,
The basic dependency example from "Smalltalk By Example" uses
Visualworks changed:with and update:with:from: methods like this:
price: aPrice
| oldPrice |
oldPrice := self price.
price := aPrice.
self changed: #price with: oldPrice
update: aSymbol with: oldPrice from: aStock
(aSymbol == #price) ifTrue:
[Transcript
cr; show: thisContext; tab; show: aSymbol; tab;
nextPutAll: 'Price changed from: '; show: oldPrice; tab;
nextPutAll: 'To: '; show: aStock price; flush]
The problem is that Squeak only implements update:with: so the
aStock price messaging doesn't work. My solution was to follow
VW's implementation by making the following changes:
Modified the changed:with: method to include from:.
changed: anAspect with: anObject
self dependents do: [:aDependent | aDependent update: anAspect with:
anObject from: self]
Added an update:with:from: method.
update: anAspect with: anObject from: aSender
^ self update: anAspect with: anObject
It took a while to see the problem and without looking at VW,
I never would have been able to figure a way. Is my fix
reasonable?
VW also implements expressInterestIn:for:sendBack: and
onChangeSend:to: methods. Anyone familiar with them and care to
provide pointers on the possibility of implementing something
similar in Squeak?
Thanks,
Chris
More information about the Beginners
mailing list