Model View Controller (MVC) is a standard design pattern practiced by many developers. Web applications will benefit from the Model View Controller (MVC) framework. But still developers continue to use the traditional ASP.NET application pattern that is based on Web Forms and postbacks. Some developers combine the two approaches as neither approach excludes the other types of Web applications.
Model View Controller (MVC) pattern creates applications that separate the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The Model View Controller (MVC) framework includes the following components:
Model
Model objects are the parts of the application that implement the logic for the application’s data domain. Model objects sometimes retrieve and store model state in a database.
For example:
- If a Product object retrieves information from a database, operate on it, and then write updated information back to a Products table in a SQL Server database.
In small applications, the model is often a conceptual separation instead of a physical one.
For example:
- If the application only reads a dataset and sends it to the view, the application does not have a physical model layer and associated classes. In that case, the dataset takes on the role of a model object.
View
Views are the components that display the application’s User Interface (UI). The User Interface (UI) is created from the model data.
For example:
- An edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Product object.
Controller
Controllers are the components that handle user interaction, work with the model. Controllers then select a view to render that displays User Interface (UI). In an Model View Controller (MVC) application, the view only displays information. The controller is responsible for user input and interaction.
For example:
- The controller handles query-string values and passes these values to the model. These models then uses these values to query the database.
As mentioned before, Model View Controller (MVC) pattern specifies where each kind of logic should be found in the application. The User Interface (UI) logic belongs in the View. Input logic belongs in theController. Business logic belongs in the Model.
This pattern will help you manage complexity in building applications, as it enables you to focus on one aspect of the implementation at a time like for instance, you can focus on the view without depending on the business logic.
The loose coupling between the three main components of an Model View Controller (MVC) application also allows parallel development.
For example:
- A developer can work on the View, a second developer can work on the Controller logic, and a third developer can focus on the business logic in the Model.
No comments:
Post a Comment