Explain the MVC model.

 
 

A commonly used design architecture for GUI applications is called Model-View-Controller, or MVC. When a GUI application works with an object, it can usually be represented with a model. The model is a complete representation of the object being used by the application. This could be a word processing document, a graphical image, a spreadsheet, or a database. The key concept is that the model is self-contained, and its representation is independent of the rest of the program. The model then provides the manipulation methods required for the outside world to use the object the model implements.
An application will then consist of any number of views of the model. There might be an edit view and a print view of a document, or several views of different pages of the document for example. Each view tracks what it needs to know about its particular perspective of the model, but each view will interact with the same model. Finally, each view has associated with it a user interface implemented as a controller object. This might include command buttons, handlers for the mouse, and so on. When a controller gets a command from the user, it uses appropriate information from the associated view to modify the model. Whenever the model changes, it will notify all views, which then update themselves. Typically there will beĀ  single Model class, and several View classes with their associated Controller classes. The Controller will respond to actions from the user, use whatever information it needs from the associated View, and send a message to the Model to modify itself. When aModel changes (and this can be caused by events other than user commands, such as synchronous events generated by a shared database being modified), it notifies all Views, which then update the display.