amnippon
amnippon

Reputation: 321

What is different between MVC and MVVM

Can anyone explain difference between

MVC(Model-View-Controller)

and

MVVM(ModelView-ViewModel) architecture

?

Upvotes: 2

Views: 3905

Answers (2)

User1075
User1075

Reputation: 885

Since MVC and MVVM are geared towards different application paradigms altogether, i.e., ASP.NET MVC for web and MVVM desktop, they need to behave in distinctly different ways, with the most noticeable distinction being the controller from MVC and the ViewModel from MVVM

The controller in MVC accepts HTTP requests, fetches data from the model, and routes that model to the view for output. In a desktop app, there is no routing or URLs; but desktop apps still feature navigation, which is part of the UI and therefore needs to be part of a good UI pattern. ViewModels are the piece that accomplishes this task, as the ViewModel in MVVM takes the responsibility of performing, or exposing the command that house all the UI logic in addition to fetching the data and data binding.

Views must behave differently as web and desktop applications use very different ways to render information for user interaction. Additionally, applications over http are considered stateless, whereas desktop applications have full connectivity over a LAN and contain and transport lots of data easily. Views in MVC only display data and perform basic client side UI duties usually with JavaScript (form submission, validation, effects, etc...). On the other hand, View in MVVM have a rich databinding and validation framework, when combined with the business logic and navigation exposed by the ViewModel, lead to a very rich User Experience

Models behave the same way in either pattern - they're full of data (and sometimes logic). You may want to use other patterns at the model level for better code organization, maintenance, and a finer separation of concerns. The repository pattern with Entity Framework is a popular pattern, and Julie Lerman has a great explanation within series of posts on it.

Within both MVC and MVVM exists the ViewModel. Despite the same name, there are marked differences within how ViewModels in either pattern work.

There are ViewModels in MVC, but they have different responsibilities than an MVVM ViewModel.

An MVC ViewModel is two or more models combined (smashed together), or a customized subset of a model or models that provides all the information necessary to its corresponding view. It's basically a hybrid model, and the best part - the views don't know the difference.

In MVVM, the ViewModel serves the same function as it does in MVC, but it also takes on the responsibility of a controller.

MVC Model and MVVM Model

MVC Model

MVvM Model

Upvotes: 2

FlatCode
FlatCode

Reputation: 23

MVVM is based on the MVC design patern.

MVVM is an implementation more specific for UI development platforms. The separation between the development of the GUI and the development of the back end makes the development process more easy in these UI development platforms.

For more info on the difference, another topic already exists on this: Link to another stackoverflow topic

Upvotes: 0

Related Questions