.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Forum >> Others >> Post New QuestionBookmark and Share Subscribe to Forum

What is the history of mvvm

Posted By: venu     Posted Date: March 20, 2012    Points:5   Category :Others
Hi Friends!

Since 3 days i am searching to learn MVVM.I had plenty of question in my mind with no answers.I thought i will get from here.

What is actually MVC,MVP,MVVM

Why we use MVC if we have the concept of n-tire architechure

Why we use MVP if we have MVC

Why we use MVVM if we have MVP

When i googled every once explaining with diagrams what is MVC,MVP,MVVM but why we use if one is there than other.

please help me, i have to give presentation today.These questions i can expect from onsite developers, thats why am asking those.

Thanks and Regards

Author: Pawan Awasthi             
Posted Date: March 21, 2012     Points: 20   

Hai Venu,
First of all appreciation for asking such a good question as it’s a bit confusion to each one and they just skip the importance of it.
First let me talk about the 3-tier (n-tier) architecture and what are the problems it has and why the new patterns came as it was the most popular architecture in their time. Also even now most of the companies are preferring 3 tier architecture for their development of the projects.

3-Tier Architecture:
One of the most important and useful architecture to create the web applications. It has mainly 3 layers-
- UI or Presentation layer (.aspx, .ascx, aspx.cs, .ascx.cs files)
- Business Logic Layer (.cs classes)
- Data Access Layer (.cs classes)
These are the 3 main layers which are used while developing the applications in 3-tier architecture.

The UI Layer or Presentation Layer contains the main User Interface which will be viewable to the users. So all the screens, User defined controls, custom controls etc comes under UI or presentation layer.

Business Logic Layer is the middle layer which is used for the development of business logics for the application so that the validation should be performed or business requirements should be fulfilled before sending data to the Data Access layer. Most of the validations are performed at this level. This layer contains the business objects and the methods used for the communication between the UI and Data Access Layer.
Here few architects think of separating this layer with Business Object layer to make the design mode readable and easy. So they create one more layer called Business Objects layer which contains the public properties which can be used throughout the application.

Data Access Layer is used for all the database operations- Insert, Update, Delete, Select etc. So all the logic which is used for these operations are performed at this layer. Calling stored procedures, passing parameters etc.

So 3-Tier architecture uses these layers for the communications and gets the result to the UI layer. The communication is done based on the request from the user by UI layer. This request goes through the business logic layer and then if any validations need to perform. It will validate and if the validation passed, it sends these requests to the Data Access Layer. The data access layer performs the database operations and then the results is send back to business layer and then to the UI.
Hope till now it’s all going good...

Now the problem comes-
1. If we add one more method in the business logic layer or in data access layer or in UI, we need to update all the layers. It means we need to implement that method in all the layer. Similarly if we remove one method from any of these layers, it will give you the error.
2. If we don’t want to perform the validations, then also it will go to business logic layer and then to the database layer. Because here all the layers are tightly bounded to each other and are dependent to each other.
3. Always the floe will be UI <---> Business Logic Layer <---> Data Access Layer
There is no skip at any place.

Why MVC?
MVC is also the components of triad means similar to the 3-tier architecture. It also has 3 layers-
- View (UI in 3-tier architecture) (.aspx, .ascx files)
- Controller (Business Logic Layer in 3-tier architecture) (.cs files)
- Model (Data Access layer in 3-tier architecture) (.cs files)
Here you can see the main difference between the UI and View is that the View does not contain .cs file attached with it. It contains only .aspx, .ascx files.
View- It is similar to the .aspx pages but with the .cs files. These are again used for the user interface.
Controller- It is slight difference than the Business Logic layer classes. It contains all the events, methods and properties related to the corresponding view.
Model- It is similar to the Data Access Layer classes where the data access logic is written. So there is no difference between the Model and Data Access Layer classes. It’s the programmer’s view that for the database operations what they use to connect to the database and do the operations.
How MVC works differently than 3-Tier architecture -
In MVC, the processing always starts from the Controller unlike from UI as compare to 3-Tier architecture. For example, the user has made the request to get the product details by supplying the product id and the URL is something like this
Here you can see the name ProductController. This is the controller class which will handle the request to process and responsible for getting the product details for the product id as 2.
If there is a controller class, there must be the view for the same controller class. Like in this URL, the corresponding Product view will be in the View section for the ProductController class. Then only the application will recognize that which view should be populated here.
In this example, first the URL will be checked for the controller class i.e. ProductController and then it will check for the next method which is used i.e.GetProductDetails and then parameter if any like in this case, id=2. It will then call the corresponding model class to get the product details for the id as 2. After retrieving the details, it will search for the Product view and populate the product view.
Now the task is done...
How it has benefit than old architecture-
1. No need to go from View <---> Controller <---> Model like in 3-tier architecture. So these layer are not tightly bounded to each other.
2. If we add any new method to the controller class or model class or add any new design to the view, it will not impact any other layer. Because if we add new method in the controller and didn’t call it, it will not execute as it is not dependent to any other layer.
3. It's not necessary that the Controller will always call the Model class, if there is no need to do any database operations, then just call the view to open the blank screen.
So these are the main advantages of MVC architecture. Due to these advantages, it’s faster in execution than the 3-Tier architecture.

Why MVP if MVC is fulfilling all the requirements?
Yes, why MVP if the MVC was good enough.
No, MVC was not good enough because there were few issues with MVC:
1. The execution starts from Controller i.e. Business Logic which is violating the rules of W3C. All the web application should start from the user Interface not from the business logic. As business logic can be exposed if proper security is not implemented.
2. Model and UI are still connected as they are attached by a logical layer.
MVP mainly came for automated unit testing. It is a derivative of the MVC where the Controller of MVC replaced by the Presenter.
When the user triggers/calls a method of view, a method of presenter without parameter (default constructor) gets invoked. And the view is displayed.
Here the execution starts always from the View so the issue 1 of MVC gets resolved.
It mainly made to test the application without View. Only by using the presenter we can test the whole application. Presenter mainly acts upon model and updates the view accordingly. So there is no coupling between the View and Model here. Whenever the Model change, automatically the view gets updated.
So all the issues of MVC gets resolved in MVP pattern.
Now if MVP was fulfilling all the requirements and no coupling between the View and Model then why MVVM??
Why MVVM if MVP was fulfilling all the requirements and solving all the issues by 3-Tier architecture and MVC?
Yes, MVVM is also called as Specialized MVC where the Controller is replaced by using the View Model.
Here the View is just below the UI layer. View Model exposes the data and command objects according to the need of View. We can say that View Model is the blue print of View which contains all the properties, methods, events which the View needs. View Model pulls the data from the Model and then accordingly the View gets updated. This works well because this model created by making the customer as the key value and keeping the user experience as the first priority. It uses the observer pattern to make the changes as soon as the View Model is updated so the user will not get any flicking of the current page. It’s looking like working with windows application.

Pawan Awasthi
(Whats App)+91 8123489140
(cell No.) +60 143651476
Author: venu             
Posted Date: March 21, 2012     Points: 20   

HI Pawan Awasthi!

I really thanx to you for the explanation.But from this article i have some questions those are not answered my question.

*Actually the n-tire architecture was introduced to implement maintenance, parallel layer development, re-usability, extendability.It means if i have changed some logic let the tax percentage increased from 10-20 in business logic layer it will not effect remainig layers.You said if we write any method we have to change the entire layers,i was just confusing if possible can u give any example.

*MVC-MVP there are not much differences i observed in this explanation between MVC and MVP and MVVM also

*And some of my colligs said MVC can't use ADo.net is it write and is not suited for windows applications is this also write

*MVP and MVVM difference not satisfied,if MVP is developed for winforms, WPF and Silverlight the what is the use of MVVM

Thanks & Regards
Dotnet Programmer
Author: Pawan Awasthi             
Posted Date: March 23, 2012     Points: 20   

Hai Venu,
<<.It means if i have changed some logic>> , It means if you change the logic like change the return type at any place (in BL/DAL or in UI), it will throw error and then you need to change it all places.

<<MVC-MVP there are not much differences>>, yes actually the MVP was made for the unit testing of the application without using the View component. Also in MVP, the execution will start from the View (W3c standards) in contrast to MVC where the execution starts from the Controller.

<<some of my collages said MVC can't use ADo.net>> this is wrong..We can use the ADO.net with MVC. But it’s recommended to use the ORM (Entity framework, Linq or any other like Sprint.Net or n-Hibernate etc) to make the object more decouple.

<<is not suited for windows applications>> this statement is also wrong. We can create the windows application using the MVC, but recommended is MVVM.

<<if MVP is developed for winforms, WPF and Silverlight the what is the use of MVVM>> , true but to make more decoupling between the layers, its recommended to use the MVVM. Here View Model use the Observer pattern to find any changes and then behave to the view accordingly. Here View model contains the blue print of the View where all the methods, Properties, commands to be written as well as the DataContext property of the View Model is assigned to the View so that if any changed in the View model, it will immediately reflects in the View and view will get updated.
Hope it will help you.

Pawan Awasthi
(Whats App)+91 8123489140
(cell No.) +60 143651476
Author: venu             
Posted Date: March 24, 2012     Points: 20   

Hi Pawan

I really thank full to you, for your explanation.
Still i have some doubts.I too searching....if u can explain any more that's more helfull me ,thanx for ur explanation again atleast i got answers from one person.

Thank u


Thanks & Regards
Dotnet Programmer

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend