View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sum2001 Midterm Review: Changed/Update

When a second passed, SecondTicker will call the nextSecond in Clock. The Clock will update its time and send a change signal to all its dependents, in this case, the ClockText object that previously register itselt to the Clock with addDependent:. The ClockText receives the message and determine whether it will respond to it or not. When the ClockText object decides to respond to the message, it query the Clock to get the time and display it to the window.
This is all good, except that the Clock doesn't actually send a changed message to the ClockText. How does that bit actually work? It's the most important step! -Lex Spoon

When a second passes by, SecondsTicker sends the nextSecond message to
its instance of the Clock class.
Clock class executes the nextSecond method, telling the time to add a
second to itself, then calling changed: on the #time.
This asks every dependent of the Clock to update: itself.
One of the Clock dependents is the ClockText; so, the ClockText
executes it's update: method; this checks to see if the time has
changed, and if it has, it erases the previous time, then queries the
Clock for the new time (this is done via model perform: query; query
for the ClockText class asks for the Time instance in the Clock class)
and displays the new information for the time at the correct location.

This is better, but the most important step is still pretty vague. Nothing is called on #time. How does the Clock inform the ClockText (in addition to any other dependents) about its change in time? -Lex Spoon

When "changed: #time" gets called, that should tell any of the dependents of Clock to perform an update, correct? So, the ClockText executes it's update:, which tells it to undraw itself, then does something like "( model perform: query ) displayAt: position" (I don't have the code here with me, so I can't say exactly what it is, but the idea is that the model has a message "perform:", which I'm assuming takes a block (query), which in turn asks the Clock for a representation of the time, which is then displayed. This is kind of an assumption, though, because, even when I had the book and lecture notes nearby, I couldn't find a good description of what exactly happens on this line).
As far as the first solution:

From the book on page 143 we learn that the Clock does send a changed message to itself by doing: self changed: #time. Ok, I see the difference, it sends it to itself. Got it!

Link to this Page