The Model-View-Controller (MVC) architectural pattern separates an application into three main groups of components: Models, Views, and Controllers.Using this pattern you will achieve "Separation of Concern" : Separate application into different layers so individual team can focus on their modules only. MVC pattern helps to create those layers and all layers are having their own responsibilities in the application which we will discuss later in this post.
All user client requests are routed to a Controller which is responsible for working with the Model to perform user actions and/or retrieve results of queries. The Controller chooses the View to display to the user, and provides it with any Model data it requires.View use that model data and rendered the final response and that will relay back to the client.
All user client requests are routed to a Controller which is responsible for working with the Model to perform user actions and/or retrieve results of queries. The Controller chooses the View to display to the user, and provides it with any Model data it requires.View use that model data and rendered the final response and that will relay back to the client.
If your application is built if you keep all layers together then it will be difficult to scale,debug and enhance the application. MVC pattern come with different responsibilities on different layers which help to scale application easily. For Example UI changes are more compare with application business rule change. so if you keep UI layers separate from business logic layers you will have chance to less errors during those UI change.
Both Controller and View depend on model however model is neither depend on Controller or View. This separation allow developer to test Model to be built and tested separately.
Now let's take a look individual responsibilities in details as mentioned.
Controller Responsibilities:-
- Controller is responsible to handle every user(client) requests, work with model and identify appropriate view to render final response.
- Controller is the initial entry point, and is responsible for selecting which model types to work with and which view to render hence it's name is given as "Controlller"
- The view only displays information; the controller handles and responds to user input and interaction
Model Responsibilities
- The Model in an MVC application represents application business logic or operations that should be performed by it.
- It also maintain the state of the application and notify the change in data.
- Model is responsible for storing and retrieving data from different data repositories.
- Strongly-typed views will typically use ViewModel types specifically designed to contain the data to display on that view
- The controller will create and populate these ViewModel instances from the model.
View Responsibilities
- Views are responsible for presenting content through the UI.
- .Net use Razor view engine to embed .NET code in HTML markup
- We should keep minimum logic in view which is only related to present data.
- View use models and create final rendered HTML which will send to client as response.
Please post your any questions in comments bellow. Thank You !
No comments:
Post a Comment