
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
386
Chapter 18
CHAPTER 18
The Model-View-Controller
Design Pattern
In the MVC paradigm the user input, the modeling of the external world, and the
visual feedback to the user are explicitly separated and handled by three types of
object, each specialized for its task.
——from Applications Programming
in Smalltalk-80(TM):
How to use Model-View-Controller (MVC), by Steve
Burbeck, available at: http://st-www.cs.uiuc.edu/users/
smarch/st-docs/mvc.html
The Model-View-Controller (MVC) design pattern separates user interface code into
three distinct classes:
Model
Stores the data and application logic for the interface
View
Renders the interface (usually to the screen)
Controller
Responds to user input by modifying the model
For example, in a toggle button, the model would store the state of the button (on or
off), the view would draw the button on screen, and the controller would set the
state of the button in the model (to on or off) when the button is clicked. But an
interface need not be visual. In some cases, the view might play a sound or, as a non-
ActionScript example, the view might make a video game controller vibrate.
MVC originated in the Smalltalk language and has been used widely for years in
many different incarnations. Though the basic principles of the pattern are easy to
understand,