Chapter 12. Model-View-Controller Pattern

According to the standard model billions of years ago some little quantum fluctuation, perhaps a slightly lower density of matter, maybe right where we’re sitting right now, caused our galaxy to start collapsing around here.

Seth Lloyd

We view things not only from different sides, but with different eyes; we have no wish to find them alike.

Blaise Pascal

The primary symptom of a controller is denial, that is I can’t see its symptoms in myself.

Keith Miller

What is the Model-View-Controller (MVC) Pattern?

The Model-View-Controller (MVC) is a compound pattern, or multiple patterns working together to create complex applications. The MVC pattern is most commonly used to create interfaces for software applications, and, as the name implies, consists of three elements.

  • Model: Contains the application data and logic to manage the state of the application

  • View: Presents the user interface and the state of the application onscreen

  • Controller: Handles user input to change the state of the application

The power of the MVC pattern can be directly attributed to the separation of the three elements without overlap in each of their responsibilities. Let’s look at each element’s responsibilities.

Model

The model is responsible for managing the state of the application. The application logic in the model performs two important tasks: it responds to requests for information about the state of the application, and takes action on requests to change the state.

View

Get ActionScript 3.0 Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.