Help understand the structure of MVVM?

I am trying to speed up using WPF and the Prism framework, which is strongly related to the MVVM pattern. I prepared a lot of different descriptions, examples and discussions on MVVM, and each of them is a little different and a little confused me.

I understand the following:

The MVVM template has 3 parts: -

  • Model - classes containing application data / information.
  • View - visual elements of the application.
  • ViewModel - logical, state and other behavior associated with visual elements. It takes data from the model and provides it (possibly with some data conversion / formatting) so that the view can use it directly.

What I'm not sure about the following:

  • Do these 3 parts include in each part of the application? Or could there be parts of the application that are outside of these three parts?
  • Is the ViewModel or some other part that is responsible for populating the model?

Thank you in advance

+4
source share
2 answers
  • Absolutely not. If they do not. If your application is simple, then everything can be handled in View, ViewModel or Model (s). If your application is complex, and best practices dictate that you go out of logic into your types (communication logic, repository logic, etc.), then you will not be stopped. MVVM only deals with the look-oriented logic in the presentation logic, the application logic in the ViewModel, and the information storage medium for transferring between them.

  • The ViewModel function is intended solely for interpreting user actions and preparing the results of logic in the Model so that the view can display this information to the user. In some cases, it makes sense that the model itself has some logic so that it can respond to user actions. However, my experience is that this Mini-ViewModel-Model project is responsible for decision-making by inexperienced developers. Once you get the real envy of MVVM, you usually don't (or want) to put any code in your models separately from the validation logic.

+3
source
  • Think of the model, ViewModel and View as logical levels that handle the business, application flow, and presentation, respectively. For example, the ViewModel class can delegate complex or multiple interactions of the user interface with a separate service that does not correspond to any particular view, but still belongs to the ViewModel layer.

  • Yes, ViewModel stands between the UI and Model.

0
source

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


All Articles