MVC Design Pattern

MVC Design Pattern

?

Model-view-controller

?

Model-view-controller (MVC) is an architectural pattern used in software engineering. In complex computer applications that present a large amount of data to the user, a developer often wishes to separate data (model) and user interface (View) concerns, so that changes to the user interface will not affect data handling, and that the data can be reorganized without changing the user interface. The model-view-controller solves this problem by decoupling data access and business logic from data presentation and user interaction, by introducing an intermediate component: the controller.

?

Pattern description

?

It is common to split into different levels of application: presentation (UI), the domain and data access. In the MVC the presentation layer further divided into view and controller. The MVC contains more than one application architecture is a typical design patterns.

?

Model
The domain-specific representation of the information on which the application works. There is a widespread misconception that the model is another name for the domain layer. Domain logic adds meaning raw data (eg, calculating if today is the user's birthday, or) the totals, taxes and shipping costs for shopping cart items.
Many applications (such as databases) to store data, use a persistent storage mechanism. MVC is specifically for the data access layer, beneath it, not to mention being understood or encapsulated by the model.
View
Renders the model into a form suitable for interaction, typically a user interface element.
Controller
Processes and responds to events, typically user actions, and may invoke changes on the model.

?

MVC is often used in Web applications, where it accumulates at the actual HTML page, and the controller is the code that generates the dynamic data and content in HTML. Finally, the model with the actual content, represented typically stored in a database or XML files.

?

Though MVC comes in different flavors, control flow generally works as follows:

?

1. The user interacts with the user interface in some way (e.g., user presses a button)
2. A controller takes the input event from the user interface, often via a registered handler or callback.
3. The controller accesses the model, possibly updating as appropriate to the user (eg, shopping cart controller information of the user).
4. A view uses the model to create the appropriate user interface (eg, view produces a screen listing the contents of your shopping cart). The view gets its own data from the model. The model has no direct knowledge of view.
5. The user interface waits for further user interactions, which begins the cycle anew.