Sunday, March 17, 2013

Model View Controller (MVC) - Simply Explained!

The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). It maintains the state and notified observers/subscribers of change in information.

View. The view manages the display of information and also facilitates interaction with user. However, it does not act on user interaction (i.e., events) - that is the job of the controller

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.



The responsibilites can be split as follows (Top down approach)

View

  • Responsible for rendering of model - UI
  • User interaction
E.g., Renders Listbox Control, Facilitates selection


Controller

  • Responsible for responding to user input
  • Instructing the Model to respond to the user input
E.g., Handles  Listbox Selection event, sends information to Model

Model

  • Responsible for storing and retrieving data
  • Maintenance of state
  • Notification of Observers  of change in state
Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl