Graphics Reference
In-Depth Information
External
Events
Application Model :
AllWorldBalls, HeroBall
DefiningNewHeroBall
CMainAppController :
Events from other GUI elements
(e.g. Slider Bars)
MainEventLoop()
(GUI API)
CViewController :
Events from large view
drawing area
CApplicationView :
Transformation for
large view drawing area
CViewController :
Events from small view
drawing area
CApplicationView :
Transformation for
small view drawing area
Figure 5.3.
Components of the ball-shooting program with small view.
Expandability. The model component supports changing of its internal
state and understands how to draw its contents. As we saw in Listing 5.4,
this means that it is straightforward to add new view/controller pairs to
increase the interactivity of the application.
5.4
Interaction among the MVC Components
The MVC framework is a tool for describing general interactive systems. One
of the beauties of the framework is that it is straightforward to support multiple
view/controller pairs. Each view/controller pair shares responsibilities in exactly
the same way: the view presents the model, and the controller allows the events
(user-generated or otherwise) to change the model component.
For an application with multiple view/controller pairs, like the one depicted
in Figure 5.3, we see that a user can change the model component via any of the
three controllers. In addition, the application itself is also capable of changing the
model state. All components must, however, ensure that a coherent and up-to-date
presentation is maintained for the user. For example, when a user drags out a new
HeroBall , both the large- and small-view components must display the dragging
of the ball, whereas the CMainAppController component must ensure that the
slider bars properly echo the implicitly defined HeroBall velocity. In the classical
MVC model, the coherency among different components is maintained with an
elaborate protocol (e.g., via the observer design pattern). Although the classical
MVC model works very well, the elaborate protocol requires that all components
communicate or otherwise keep track of changes in the model component.
Search WWH ::




Custom Search