M-V-C: What about the Controller?
M V C What about the Controller?
There is a third tier to the model/view structure: the controller. Controller code is code that manages the interactions among events, models, and views. Factory methods, and creation and destruction code in general fall into the realm of the controller.
Model-View-Controller (MVC), illustrated in Figure 17.1, is a design pattern that is used for applications in which a variety of views of the same data need to be maintained. The pattern specifies that the model code (responsible for maintaining the data), the view code (responsible for displaying all or part of the data in various ways), and the controller code (responsible for handling events that impact the data or the model) be kept as separate as possible from one another. This separation allows views and controllers to be added or removed without requiring changes in the model.
Figure 17.1. Model-View-Controller pattern
A controller class is a class whose specific purpose is to encapsulate controller code. A complex application might have multiple controllers for the different sub-components, or layers, of the application.
Qt 4 classes that are considered controller classes include QApplication, QAction, and their derived types. Code that connects signals to slots can also be considered controller code. As we shall see, keeping controller code out of model and view classes will yield additional design benefits.
Dynamic Form Models
|