Squeak and Events (Observer pattern)
Last updated at 7:14 pm UTC on 4 December 2007
Here is an example which shows how to use events to implement a changed, update: behavior (observer pattern).
This is the way to avoid all these ugly update method full of case statements.
lifes := aNumber.
self trigger: #lifesChanged.
domain := MyModel new.
domain when: #lifesChanged send: #lifesChanged to: self.
Take care the following in for Squeak32 the interface slightly changed in 3.3
lifeDisplay value: domain lifes
Also see Morphic Event Handling.
Also see Announcements Framework, a new framework for doing this kind of thing faster and simpler.