links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
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.

Stephane Ducasse

MyModel>>lifes: aNumber
lifes := aNumber.
self trigger: #lifesChanged.

super initialize.
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.