The MVC Design Pattern

The Model-View-Controller architecture is an object-oriented framework and well-known design pattern for building applications and reusable GUI components. MVC prescribes a way of breaking an application or component into three parts: the model, view, and controller. The original motivation for this separation was to map the traditional input, processing, output roles into the GUI realm:

Input > Processing > Output

Controller > Model > View

The user input, system function and state, and visual feedback to the user are separated and handled by controller, model, and view respectively. The MVC Triad represents the basic MVC triad and lines of communication.

The MVC Triad

 

The model is really the cornerstone of the triad. As its name implies, its job is to model some real-world system by emulating its state and functionality. Models define queries for reporting state, commands for altering state, and notifications to inform observers (views, for example) that a change in state has occurred. The controller is responsible for defining the behavior of the triad. Its job is to receive mouse and keyboard input and map this user stimulus into application response – for example, by executing the model’s commands. The view manages a rectangular area of the display and is responsible for data presentation and hit testing. (Hit testing calculates the object at a given position on screen.) And due to its observer relationship with the model, new views can be defined and attached to a model while holding the model’s interface constant.