
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
398
|
Chapter 18: The Model-View-Controller Design Pattern
An MVC Clock
With our core MVC structure in place, we can create a real-world MVC applica-
tion—a clock with analog and digital displays. The default MVC framework and
source files for the clock are available at http://moock.org/eas2/examples.
Figure 18-3 shows the graphical user interface for the clock. Notice that in addition
to the analog and digital displays, the clock includes buttons to start, stop, and reset
the clock’s time.
Our clock application includes seven classes, as follows:
Clock
The main application class, which creates the MVC clock
ClockModel
The model class, which tracks the clock’s time
ClockUpdate
An info object class that stores update data sent by ClockModel to all views
ClockAnalogView
A view class that presents the analog clock display
ClockDigitalView
A view class that presents the digital clock display
/**
* Returns this controller's view.
*/
public function getView ( ):View {
return view;
}
}
Figure 18-3. The Clock graphical user interface
Example 18-4. The AbstractController class (continued)