The Model-View-Controller design pattern (MVC for short) is conceived to better separate the three essential functions of an interactive application:
- The business logic of the application (the Model).
- The interface presented to the user (the View).
- The control of the interaction triggered by the user's actions (the Controller).
The Model encapsulates the business actions required for answering a user's request and keeps the state of the application. The Model should ignore the format in which requests are posed, and the way in which the response is constructed and presented to the user. The View embodies the presentation logic for assembling the user interface. The View should ignore where the results to present come from and the details of the request originating such results. The Controller is the traffic cop of the architecture, responsible of interpreting the user's request, producing the appropriate request for action, examining the result of each action, and deciding what to do next. The Controller is totally unaware of the business logic of the action it invokes, and of the presentation logic of the View. The computation is activated by a user's request for some content or service. The request is intercepted by the Controller, who is responsible of deciding which action to take for servicing it. The Controller dispatches the request to the suitable component of the Model. The Model incorporates the business logic for performing the action, and executes such logic, which updates the state of the application and produces a result to be communicated to the user. The change in the Model triggers the most appropriate View, which builds the presentation of the response. Such presentation typically embodies interaction objects, whereby the user may pose a new request and reactivate the computation process. |