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

Part I: Introduction to C++ and Qt 4

C++ Introduction


Introduction to Qt



Inheritance and Polymorphism

Part II: Higher-Level Programming


Introduction to Design Patterns


Generics and Containers

Qt GUI Widgets


Validation and Regular Expressions

Parsing XML

Meta Objects, Properties, and Reflective Programming

More Design Patterns

Models and Views

Qt SQL Classes

Part III: C++ Language Reference

Types and Expressions

Scope and Storage Class

Statements and Control Structures

Memory Access

Chapter Summary

Inheritance in Detail

Miscellaneous Topics

Part IV: Programming Assignments

MP3 Jukebox Assignments

Part V: Appendices

MP3 Jukebox Assignments


MP3 Jukebox Assignments

An Introduction to Design Patterns in C++ with Qt 4
An Introduction to Design Patterns in C++ with Qt 4
ISBN: 0131879057
EAN: 2147483647
Year: 2004
Pages: 268

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net