Click here to Skip to main content
15,861,168 members
Articles / General Programming / Architecture

Learning MVC - Part 1: Introduction to MVC Architecture and Separation of Concerns

Rate me:
Please Sign up or sign in to vote.
3.98/5 (99 votes)
17 Mar 2015CPOL3 min read 377.8K   1K   300   51
Introduction to MVC architecture and Separation of Concerns.

Introduction 

 Image 1

After having gone through numerous of blogs and articles, I came to a conclusion that very few of the genuine writers have explained the topic from the basic to full-fledged, while including a working application. My effort in this MVC articles series will be to cover almost all the aspects of MVC starting from creating a simple app and connecting with the database with various Microsoft providers. We’ll be gradually moving forward part by part so we can understand and practically implement every scenario.

Road Map

 Image 2

All set? Let's start our journey with Part1.  

Part1: Introduction to MVC architecture and Separation of Concerns

Topics to be Covered

  1. What does MVC mean.
  2. Understanding MVC Architecture.
  3. Separation of Concerns

Players

Model: The business entity on which the overall application operates. Many applications use a persistent storage mechanism (such as a database) to store data. MVC does not specifically mention the data access layer because it is understood to be encapsulated by the Model.

View: The user interface that renders the model into a form of interaction.

Controller: Handles a request from a view and updates the model that results a change in Model’s state.

To implement MVC in .NET we need mainly three classes (View, Controller and the Model).

MVC Architecture

           The choice of MVC comes when we go for a solution where the separation of concerns, ease of maintainability and extensibility of an application matters a lot. As per the architecture given below, we can see the request-response flow of a MVC application.

Image 3

The architecture is self explanatory. The browser (as usual) sends a request to IIS, IIS searches for the route defined in MVC application and passes the request to the controller as per route, the controller communicates with the model and passes the populated model (entity) to View (front end), Views are populated with model properties, and are rendered on the browser, passing the response to browser through IIS via controllers which invoked the particular View.

Separation of Concern

As per Wikipedia 'the process of breaking a computer program into distinct features that overlap in functionality as little as possible'. MVC design pattern aims to separate content from presentation and data-processing from content. Theoretically sound, but where do we see this in MVC? One place is reasonably clear - between the data-processing (Model) and the rest of the application.

When we talk about Views and Controllers, their ownership itself explains separation. The views are just the presentation form of an application, it does not have to know specifically about the requests coming from controller. The Model is independent of View and Controllers, it only holds business entities that can be passed to any View by the controller as required for exposing them to the end user. The controller is independent of Views and Models, its sole purpose is to handle requests and pass it on as per the routes defined and as per the need of rendering views. Thus our business entities (model), business logic (controllers) and presentation logic (views) lie in logical/physical layers independent of each other.

Conclusion

Now that we know why and where to use MVC, in the next part of the series we’ll be creating an MVC application from scratch, and exploring the practical implementation of MVC.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect https://codeteddy.com/
India India
Akhil Mittal is two times Microsoft MVP (Most Valuable Professional) firstly awarded in 2016 and continued in 2017 in Visual Studio and Technologies category, C# Corner MVP since 2013, Code Project MVP since 2014, a blogger, author and likes to write/read technical articles, blogs, and books. Akhil is a technical architect and loves to work on complex business problems and cutting-edge technologies. He has an experience of around 15 years in developing, designing, and architecting enterprises level applications primarily in Microsoft Technologies. He has diverse experience in working on cutting-edge technologies that include Microsoft Stack, AI, Machine Learning, and Cloud computing. Akhil is an MCP (Microsoft Certified Professional) in Web Applications and Dot Net Framework.
Visit Akhil Mittal’s personal blog CodeTeddy (CodeTeddy ) for some good and informative articles. Following are some tech certifications that Akhil cleared,
• AZ-304: Microsoft Azure Architect Design.
• AZ-303: Microsoft Azure Architect Technologies.
• AZ-900: Microsoft Azure Fundamentals.
• Microsoft MCTS (70-528) Certified Programmer.
• Microsoft MCTS (70-536) Certified Programmer.
• Microsoft MCTS (70-515) Certified Programmer.

LinkedIn: https://www.linkedin.com/in/akhilmittal/
This is a Collaborative Group

779 members

Comments and Discussions

 
QuestionOne request to come with article regarding unit testing EF repository Pin
Tridip Bhattacharjee8-Mar-17 21:24
professionalTridip Bhattacharjee8-Mar-17 21:24 
AnswerRe: One request to come with article regarding unit testing EF repository Pin
Akhil Mittal9-Mar-17 16:16
professionalAkhil Mittal9-Mar-17 16:16 
Question[My vote of 1] Waste of time. Pin
2374113-Dec-15 0:36
2374113-Dec-15 0:36 
QuestionComplete nonsense Pin
Gerd Wagner10-Dec-15 10:18
professionalGerd Wagner10-Dec-15 10:18 
GeneralNicely explained Pin
Vikas Sharma1-Jul-15 23:16
professionalVikas Sharma1-Jul-15 23:16 
GeneralRe: Nicely explained Pin
Akhil Mittal1-Jul-15 23:19
professionalAkhil Mittal1-Jul-15 23:19 
GeneralMy vote of 5 Pin
udeep kansal17-Jun-15 7:20
professionaludeep kansal17-Jun-15 7:20 
GeneralRe: My vote of 5 Pin
Akhil Mittal17-Jun-15 22:24
professionalAkhil Mittal17-Jun-15 22:24 
QuestionGood explanation Pin
Its Tinku3-Feb-15 0:42
Its Tinku3-Feb-15 0:42 
AnswerRe: Good explanation Pin
Akhil Mittal8-Feb-15 20:41
professionalAkhil Mittal8-Feb-15 20:41 
GeneralMy vote of 1 Pin
Syed M Hussain30-Jun-14 2:14
Syed M Hussain30-Jun-14 2:14 
GeneralMy vote of 1 Pin
Member 1001700228-May-14 21:18
Member 1001700228-May-14 21:18 
GeneralMy vote of 1 Pin
deba prasad satapathy22-Apr-14 22:42
deba prasad satapathy22-Apr-14 22:42 
GeneralRe: My vote of 1 Pin
Akhil Mittal22-Apr-14 22:44
professionalAkhil Mittal22-Apr-14 22:44 
GeneralMy vote of 2 Pin
Gandalf_TheWhite18-Feb-14 20:43
professionalGandalf_TheWhite18-Feb-14 20:43 
GeneralRe: My vote of 2 Pin
Akhil Mittal19-Feb-14 5:00
professionalAkhil Mittal19-Feb-14 5:00 
GeneralRe: My vote of 2 Pin
Gandalf_TheWhite19-Feb-14 19:15
professionalGandalf_TheWhite19-Feb-14 19:15 
GeneralMy vote of 2 Pin
Marco Bertschi10-Sep-13 5:46
protectorMarco Bertschi10-Sep-13 5:46 
GeneralRe: My vote of 2 Pin
Akhil Mittal10-Sep-13 17:46
professionalAkhil Mittal10-Sep-13 17:46 
GeneralMy vote of 2 Pin
BillWoodruff10-Sep-13 3:11
professionalBillWoodruff10-Sep-13 3:11 
GeneralRe: My vote of 2 Pin
Akhil Mittal10-Sep-13 17:45
professionalAkhil Mittal10-Sep-13 17:45 
GeneralMy vote of 5 Pin
_Vitor Garcia_9-Sep-13 22:13
_Vitor Garcia_9-Sep-13 22:13 
GeneralRe: My vote of 5 Pin
Akhil Mittal9-Sep-13 22:48
professionalAkhil Mittal9-Sep-13 22:48 
QuestionThis sould not be an article PinPopular
Pete O'Hanlon9-Sep-13 2:28
subeditorPete O'Hanlon9-Sep-13 2:28 
AnswerRe: This sould not be an article Pin
Akhil Mittal9-Sep-13 3:42
professionalAkhil Mittal9-Sep-13 3:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.