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

Discussion 4 - Jiasheng He

Helping the MVC Novice (Summer 2002)

One of the members of a CS2340 team unfortunately missed all of the lectures on UI because of his European vacation. Heís trying to get his first MVC interface to work, and heís asking you for help. Answer his questions below.

a. (4) "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?"

Our book says that "views make themselves dependant on a model object," meaning that each view has a model that it associates with. The specific code to do this is in the format model addDependent: view. ClockText has a model instance variable in it, and so we use that to set the view inside the setter for model (which uses an aModel temp variable) by saying aModel addDependent: self.

b. (5) "Now, the time has changed. How does the ClockText find out that it has to display a new time?"

ClockText will know that the time has changed because it is now dependant on Clock. Clock will use its own change method to announce a change, and that method tells the views (including ClockText) to update. The next steps would have ClockText asking for the right time from Clock, then changing the display to match that time.

c. (6) "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?!?"

If Clock displayed the correct time, then the parts wouldn't be separate and you wouldn't have a MVC structure. One of the main points of having MVC is so that you can have one model that can be used with multiple views, or one view that can be used for multiple models.

Links to this Page