Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are the advantages of Model-View-ViewModel (MVVM) pattern worth the overhead?

The question is stated in the subject: are the advantages of Model-View-ViewModel (MVVM) pattern worth the overhead?

In many cases, implementing the view model involves quite significant overhead of duplicating the Model properties and sometimes synchronization between Model and ViewModel data members. For example, currently in Silverlight 4 & WCF RIA, View Models are not generated (if the developer follows the MVVM pattern, it is up to him to create the view models, often duplicating the corresponding Model's properties at ViewModel, that do nothing significant but refer to Model as the storage).

Why not extending the Model class, providing additional properties to make it easy to be consumed by the View instead?

like image 223
Dmitry Avatar asked Apr 12 '11 01:04

Dmitry


People also ask

Why do we need Model-View-ViewModel pattern MVVM pattern?

Like many other design patterns, MVVM helps organize code and break programs into modules to make development, updating and reuse of code simpler and faster. The pattern is often used in Windows and web graphics presentation software.

What is the advantage of ViewModel?

The ViewModel class allows data to survive configuration changes such as screen rotations. The ViewModel class also helps in implementing MVVM(Model-View-ViewModel) design pattern which is also the recommended Android app architecture for Android applications by Google.

What are the advantages and disadvantages of MVVM?

Advantages. MVVM facilitates easier parallel development of a UI and the building blocks that power it. MVVM abstracts the View and thus reduces the quantity of business logic (or glue) required in the code behind it. The ViewModel can be easier to unit test than in the case of event-driven code.

What are the benefits of MVVM design pattern?

MVVM treats both Activity classes and XML files as views, and ViewModel classes are where you write your business logic. It completely separates an app's UI from its logic.


1 Answers

Why not extending the Model class, providing additional properties to make it easy to be consumed by the View instead?

Effectively that is what the PresentationModel is for. Which MVVM is strongly based on. The difference is that the ViewModel is the model for the view and not the model for the data. So you are concerned around more how the view behaves with the data.

If you have a simple UI that all it does is present the model then I would suggest expose the Model on a property of the ViewModel and bind to that. Make sure though the model does implement INotifyPropertyChanged etc.

The power of the ViewModel is when you have things to do in response to a user action. The ViewModel can then support Commands, calling out to services and validation and thus leaving the Model as a data container

like image 167
aqwert Avatar answered Oct 13 '22 00:10

aqwert