
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
An MVC Clock
|
415
necessarily a direct visualization of the model. Here, the button states depend on
whether the clock is running, not on the current time. That is, this view depicts the
model’s
isRunning property, which is equally as valid as the other views depicting the
hour, minute, and second properties.
Now let’s move on to the ClockController class, which handles input for ClockTools.
Again, the ClockAnalogView and ClockDigitalView views use the default controller
created by AbstractView, but our ClockTools class creates its own controller.
The ClockController Class
The ClockController class extends AbstractController. It provides event handling for
the user interface created by the ClockTools view.
To change the state of the ClockModel, the ClockController class defines the follow-
ing methods:
startClock( )
stopClock( )
resetClock( )
setTime( )
setHour( )
setMinute( )
setSecond( )
Notice that many of the preceding methods are wrappers over methods in the
ClockModel class. Some of them act as direct pass-through methods (e.g., startClock( )
and stopClock( )), whereas others add some convenience functionality (e.g., the ability
to independently set a single aspect of the time, such as the hour, minute, or second).
But the real duty of the ClockController class is fulfilled by its click( ...