O'Reilly logo

Professional Cairngorm™ by Jeremy Wischusen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.4. The Model View Controller Pattern

As mentioned in the last section, the MVC pattern is generally more concerned than others with how an application is structured than it is in the solution to a particular problem. The general idea is to divide application code into three tiers called the model, the view, and the controller.

The GOF book describes the MVC pattern as follows:

MVC consists of three kinds of objects. The Model is the application object, the View is the screen presentation, and the Controller defines the way that the user interface reacts to user input.

In applications that do not use the MVC pattern, these three tiers tend to be mixed together and scattered across the application. This makes changing any given part of the application more difficult, since to change something like the way that a view represents its data, you may have to update the underlying data. Additionally, the same data may be duplicated across multiple views, requiring each view to be updated.

In addition to splitting applications into tiers, the MVC pattern also dictates how these tiers interact, the responsibilities of each tier, and which tiers have knowledge of the other tiers.

The book Head First Design Patterns (Eric Freeman, Elisabeth Robson, Kathy Sierra, and Bert Bates, O'Reilly, 2004) describes the responsibilities of each tier as follows:

  • Model: Holds the data, state, and application logic

  • View: Presents the data contained in the model to the user

  • Controller: Takes user input and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required