Sp2001 Midterm Review: Dealing with the European Vacation
Fix your friend's understanding of MVC here:
Does Anyone know this.......?
Any help with this one would be appreciated
I don't know if you have already figured this out, but I was able to find the answers to all three parts in the book between pages 140 and 145.
hope this helps!!!
Amy, why don't you post your answers, and I'll give you feedback on them. Mark Guzdial
::takes a deep breath and crosses fingers::
Qn "Okay, Iíve got this Clock object, and Iíve got this ClockText thatís going to display the time. When Iím first setting up the text area, how do I tell Clock that this instance of ClockText is a view for it?"
a) Since views are dependencies on model objects, you can add a view to a model with the addDependant: meathod which is actually part of the Object class but is still understood by Model. In this case, we know that ClockText holds a model instance variable, so we can set ClockText to be its view (dependant) with this code: myModel addDependent: self.
Qn "Now, the time has changed. How does the ClockText find out that it has to display a new time?"
b) Since we have set up ClockText to be a dependent of the model (Clock) we can use dependancy properties to alert ClockText of the time change. Every second clock sends out a NextSecond message to tell all views of Model to update. ClockText uses the query message to get the updated information, and it uses Update to perform that change.
Qn "That seems like an awful lot of work! Why not just have the Clock display the correct time at each second? Why involve ClockText at all?!?"
c)It is a good idea to separate the displaying (View) from the rest because it adds to the MVC design. ClockText is necessary for actually displaying the text. Since it is not part of Clock, it is reusable code, and can be used in other things very easily. It is also a good idea to separate this for future changes to the clock. If the text display is separate from the clock, then it is very easy to change the clock's output from analog to digital or whatever. Amy Hurst
could anyone bother to confirm this if it's right?
Looks good to me –Amir Ebrahimi
Sorry I didn't see this until after the midterm. a and c look really good. b is subtly incorrect. The Clock merely announces a "change." INDIRECTLY (and that's critical), the ClockText gets told to update. Then the ClockText asks the Clock for the time. "Every second clock sends out a NextSecond message to tell all views of Model to update." isn't quite right. Mark Guzdial