Comparison between a three-layer drawing and MVVM

I do not know MVVM. I always follow a 3-layer layer, where one layer is the user interface, the other layer is the business layer, and the last layer is the data access layer.

in this layer, we send a request from the user interface to the business layer, and the business layer interacts with the data access layer. everything goes well in this template, then my question is why you need to learn MVVM. what is the advantage of MVVM. what things can be done very little using MVVP. Please discuss in detail. thanks.

+4
source share
4 answers

Layers

Unlike what ppl wrote in front of me - the MVVM template does not consist of splitting the UI layer into 3 layers, it is about splitting the UI layer into two additional layers - View and ViewModel.

therefore, if we had DAL, BLL and UI, now we have Model (DAL and BLL) and ViewModel + View (and not just one UI layer).

it's still 3 layers, but organized differently (and if you really think about it - DAL was never really a layer - it was not a helper class, so the above 3-layer was actually only 2 levels, which now become 3 layer in MVVM).

Causes

if you think about it, you'll see that in a three-layer architecture, usually the user interface is mixed with the view code and the application logic code. this violates the SRP (single responsibility principle) and is bad for several reasons. in MVVM, the UI layer is split into two layers. ViewModel, which is responsible for application logic and presentation, which is responsible exclusively for presentation.

This allows you three very important things:

  • best code Maintaining health.

  • easier to work with the constructor VS and Blend. aka Miscibility. (this is arguably the most powerful MVVM feature. It really improves performance)

  • allows you to test ViewModel with automatic tests, while until now we had to test the user interface itself, and automatic tests in the user interface are complicated. This is called testability.

on a personal note; I have been writing in n-level architecture for many years. I started practicing MVVM a little over a year ago. In some cases, it can be a rough trip, but man, it is really worth the effort.

+12
source

MVVM is designed to create a user interface layer. This is a template that allows you to interact very well between your business objects and the user interface. You do not need to change your 3-level template. MVVM is at a different level of abstraction.
Here you will find a very good video representing MVVM and possibly answering many questions.

+4
source

MVVM is perhaps a three-layer architecture. These layers all exist in one application.

The β€œ3-layer” also sometimes refers to an n-tier architecture , which is more about dividing the user interface, service level and data layer into separate servers. If you have this kind of layers, then MVVM will not replace it. It will only increase the user interface layer by dividing it into three levels.

Here is an MVVM entry that shows some connection between classic MVC, MVP, and MVVM:

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

Also see my answer to this other question . This explains some reasons for using MVVM in older versions of MVC .

+3
source

MVVM is of particular importance to WPF, Silverlight / Moonlight, and Windows Phone 7 because it takes advantage of the powerful data binding built into these structures.

+2
source

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


All Articles