MVC Series - Basics of MVC Architectural Pattern

Recently few days back i gone through numerous of blogs and articles ………… as usual , I came to a conclusion that very few writers have explained the topic from the basic, while including a working application. Most of the articles based on questions and answers which increase confidence of person for interview but not knowledge. I am going to put my effort in this articles series to cover almost all the aspects of MVC starting from small examples including database operations with various Microsoft providers. We’ll be gradually moving forward part by part so we can understand and practically implement every scenario.

Let’s start with following points.
  1. What does MVC mean.
  2. Understanding MVC Architecture.
What does MVC mean.
MVC is not a design pattern, it is an Architectural pattern that describes a way to structure our application and the responsibilities and interactions for each part in that structure.
MVC separate the application object model from GUI, originally invented around 80s. Then later on it has become a widely accepted common design pattern. The main objective behind this pattern is to decouple the view of the data (presentation layer) from the actual data processing so that the same model can be used for various views. This is achieved by using three different types of objects that interact with each other in loosely coupled manner with their discreet set of tasks.
·         Model
·         View
·         Controller
The model is responsible for managing the data of the application. It responds to the request from the view and it also responds to instructions from the controller to update itself.
View is the presentation of data in a particular format, triggered by a controller's decision to present the data. They are script based templating systems like JSP, ASP, PHP and very easy to integrate with AJAX technology.
The controller is responsible for responding to user input and performs interactions on the data model objects. The controller receives the input, it validates the input and then performs the business operation that modifies the state of the data model.

MVC Architecture
Following diagram is self explanatory to understand the architecture and flow data

Ø  Request is being taken from User to controller.
Ø  Controller processes the request from the user and creates a data Model of that particular request.
Ø  Data model that is being created is then passed to View that handles the frontend or the design.
Ø  View then transforms the Data Model by using its own functions in an appropriate output format.
Ø  The output format that is being given by the View is then gets rendered to the Browser and the View will be seen by the user.

Let’s have practical look over mvc components


Ø  MVC model is basically a C# or VB.NET class
Ø  A model is accessible by both controller and view
Ø  A model can be used to pass data from Controller to view
Ø  A view can use model to display data in page.


Ø  View is an ASPX page without having a code behind file
Ø  All page specific HTML generation and formatting can be done inside view
Ø  One can use Inline code (server tags ) to develop dynamic pages
Ø  A request to view (ASPX page) can be made only from a controller’s action method
Ø  Controller is basically a C# or VB.NET class which inherits system.mvc.controller
Ø  Controller is a heart of the entire MVC architecture
Ø  Inside Controller’s class action methods can be implemented which are responsible for responding to browser OR calling views.
Ø  Controller can access and use model class to pass data to views
Ø  Controller uses ViewData to pass any data to view

We will discuss one working example in next post……..thanks………

No comments:

Post a Comment