Monday, May 25, 2009

Model View Controller (MVC) Pattern

The Model View Controller (MVC) pattern implements the Separation of Concerns Principle at application level. Back-end and front-end logic are separated with a controller layer that glues them together while keeping them separated at the same time. This is why complex application are more manageable and maintainable when implementing this pattern. The separation between the two makes it easy to change the implementation of one, without changing the implementation of the other. The controller is the one that will suffer changes in order to the new implementation.


The model represents the data and the business rules of your application. It usually referred to as the back-end and consists of two layers: the persistence layer, and the business layer. The persistence layer is responsible for retrieving and storing data in a database while the business layer implements the business rules that manage the data. The model may notify the view about changes in its state.

The view is the layer that implements the interface with the user. The interface displays the data of the model in a human understandable manner. The view may query the state of the model or respond to model state change notifications to keep itself synchronized with the model.

The controller translates user actions into actions that activate business processes in the model. Running this business processes usually produce changes in the state of the model. The controller chooses which view to display to the user as a result of a user action. When the chosen view will be rendered, the current state of the model will be displayed to the user.

No comments:

Post a Comment