Unique Benefits of MVVM

A stackoverflow search will result in several posts that contain similar headers, but that's another question. Since this is not a discussion site, I have to ask another question.

What unique benefits do I get from using MVVMs that I cannot get from any other implementations? MVC NTiers or something else. I'm really not looking for the identification features that make MVVMs different. I am looking for things that cannot be done in anything other than MVVM. My current knowledge of this makes me think that MVVM is another way of doing the same thing, which introduces more complexity, and then say nTiers. I do not want to approach from an angle that introducing this complexity is a negative thing. If this is justified by providing unique benefits, I would like to know.

Deep google, only activated MVVM restrictions. It did not bring these unique benefits.

+4
source share
4 answers

MVVM is just a tiny twist on the Model-View-Presenter class template. The only difference with MVVM is that your view-model classes are designed specifically to play well with the data binding functions that are built into WPF and Silverlight, to minimize the need for any code in the view itself (keeping it clean XAML markup view, which can be edited / replaced in the designer). If you are using WPF or Silverlight, this is definitely worth a look carefully. If you use anything else, this is not applicable.

+3
source

The only advantage I can come up with relates to the MVVM pattern over MVP (of which it is an option) is that in MVVM you do not need to explicitly bind View to ViewModel (Presenter), as you will be in the MVP implementation. This is provided by the facilities provided by WPF. (BindingExpressions are most important). In MVP, you define an interface that represents how the presenter can interact with the view (IxxxxView is a common naming pattern), and when you create the presenter, you pass it a view interface (which is attached to it in the view instance). It also allows for some viewing options on top of a common presenter.

In MVVM, you do not explicitly define this interface. You define your ViewModel and use Binding to bind the ViewModel (logic) to the view (s). There is no built-in knowledge about the ViewModel in the view, since bindings (if they are executed in XAML) are allowed at runtime (or sometimes in the designer). Theoretically, a WPF application should be fully manageable without a user interface.

The advantage that you get from MVVM / MVP / MVC is, first of all, the separation of problems between presentation and business logic and what this allows. It allows specially qualified roles (read: actual graphic designers) to work on a presentation without having anything to do with knowledge of C # / VB.NET code. They can create a presentation, and the developers will come along and pick things up after that.

In addition, developers now have templates that can automate code testing using unit tests. Because applications can be managed (mostly) without a user interface, unit tests are a great tool that allows developers to really implement all the code they write.

In fact, this does not compare the comparison between N-Tier and MVVM, although I do not know that this is a comparison of apples with apples. Perhaps WPF MVVM applications are N-tier applications with multiple logical layers in a solution.

Ultimately, MVVM / MVP / MVC are all very comparable models with the same benefits. One thing though, however, is that MVVM, as I know, can only be used when WPF / Silverlight is the preferred presentation technology. And I guess this is the only advantage of MVVM. This is the specific and optimal template for us in WPF / Silverlight. After using MVVM, it would be inconvenient to use any other template in WPF.

+6
source

MVVM is simply a technology for implementing a presentation model template.

The main advantage is that if you maintain a clean separation of markup and code , you can focus on the behavior of the application (that is, the code) and let professional graphic designers use the look and feel of the application.

These two tasks can work in parallel by two different people using different tools (for example, Visual Studio vs. Expression).

You can get many benefits with other templates, but MVVM specifically plays in support of the tool provided by Microsoft.

+3
source

Here's an article on the Java framework using MVVM ("view model"), MVP ("passive view"), and hybrid MVVMP / MVC ("control controller"). I think this is relevant to the question, as he compares the templates and sees that this is done outside of WPF, it can help in forming an opinion on what is the template, what is the structure and what are the choices and forces in trying to use event oriented graphical interfaces graphical interface.

Implement event-driven graphical GUIs using the Java AJAX ZK framework

The obvious advantage he mentions in MVVM is that you can use the same view model with different screens. Thus, the presentation model can be separated by a mouse screen and a touch screen. The view model may be displayed using a read-only screen for some users and a different layout reading screen for other users. This is a side effect of modeling state and behavior if the screen is independent of the layout, which is the view.

0
source

Source: https://habr.com/ru/post/1347331/


All Articles