Graphics Reference
In-Depth Information
class CMainAppController {
private : CViewController aViewController; // For drawing and mouse interaction
Define aSmallView : CViewController aSmallView ;
// For the small view
public :
Source file. Pseudocode; no
corresponding source file.
void Initialize(CApplicationModel aModel)
{
TheModel = aModel
// initialize the drawing area
aViewController.Initialize(aModel, areaForDrawing)
// ... identical to the event service registration as Listing 5.3
Init aSmallView : aSmallView .Initialize(aModel, smallDrawingArea )
}
}
Listing 5.4. Implementing the small view for the ball-shooting program.
For simplicity, Figure 5.2 shows two identical view/controller pairs. In gen-
eral, a new view/controller pair can be created to present a different visualization
of the application state. For example, with slight modifications to the view compo-
nent's transformation functionality, the large view of Figure 5.2 can be configured
into a zoom view, and the small view can be configured into a work view, where
the zoom view can zoom into different regions (e.g., around the HeroBall )and
the work view can present the entire application space (e.g., all the free-falling
balls).
Figure 5.3 shows the components of the solution in Listing 5.4 and how these
components interact. We see that the model component supports the operations
of all the view and controller components, and yet it does not have any knowl-
edge of these components. This distinct and simple interface has the following
advantages.
Simplicity. The model component is the core of the application and usually
is the most complicated component. By keeping the design of this compo-
nent independent from any particular controller (user input/events) or view
(specific drawing area), we can avoid unnecessary complexity.
Portability. The controller component typically performs the translation of
user actions to model-specific function calls. The implementation of this
translation is usually simple and specific to the underlying GUI API. Keep-
ing the model clean from the highly API-dependent controller facilitates
portability of a solution to other GUI platforms.
Search WWH ::




Custom Search