Thursday, May 29, 2008

Model View Controller

[Extracts from Pattern Oriented Software Architecture Buschmann et al.]

The Model-View-Controller architectural pattern (MVC) divides an interactive application into three components. The model contains the core functionality and data. Views display information to the user. Controllers handle user input. Views and controllers together comprise the user interface. A change-propagation mechanism ensures consistency between the user interface and the model.

Context:
Interactive applications with a flexible human-computer interface.

Problem:
User interfaces are especially prone to change requests. The user interface platform of long-lived systems thus represents a moving target.Different users place conflicting requirements on the user interface. Consequently, support for several user interface paradigms should be easily incorporated.
The following forces influence the solution:

  • The same information is presented differently in different ways.
  • The display and behavior of the application must reflect data manipulations immediately. Changes to the user interface should be easy and even possible at run-time.
  • Supporting different 'look and feel' standards or porting the user interface should not affect code in the core of the application.
Solution:

Model:The model component encapsulates core data and functionality. The model is independent of specific output representations or input behavior.

View:View components display inform~tion to the user. A view obtains the data from the model. There can be multiple views of the model.

Controller:Each view has an associated controller component. Controllers receive input, usually as events. Events are translated to service requests for the model or the view. The user interacts with the system solely through controllers.

No comments: