0

Here are two links which briefly describe the difference between the two: stateless, stateful

In short in the "Stateless" scenario we bind views directly to models, view models just expose the whole objects, not their properties, so we don't need any synchronization between models and view models.

In the "Stateful" scenario we make a copy of a model object and bind it to a view.

Are there any downsides in the "Stateless" scenario? Because it seems like it's a way to go by default. What stops us from implementing INotifyDataErrorInfo, INPC and all the stuff at the level of models?

1

What stops us from implementing INotifyDataErrorInfo, INPC and all the stuff at the level of models?

That how the model is described by the business and how it is shown in the UI can (and will) be different.

While simple scenarios might make it seem that models and UIs are exactly the same, reality is not so simple. ViewModel's primary purpose is to transform the business domain model into form that is easy to bind to UI.

  • Can't we rely on converters in order to cover the necessity for transforming model values? – EngineerSpock Jun 10 '16 at 12:08
  • @EngineerSpock No. Converters are too simple. I'm not talking about simple 1:1 mappings. I'm talking about drastic changes in shape of the model and in exposed behavior. – Euphoric Jun 10 '16 at 12:15
  • Maybe, it would be better in such cases to roll out model wrappers? (though, seems like any benefits of "stateless" VM in this case disappear). – EngineerSpock Jun 10 '16 at 12:19
  • @EngineerSpock What is difference between "model wrapper" and ViewModel? To me, the ViewModel is the "model wrapper". – Euphoric Jun 10 '16 at 12:22
1

Nearly ever user interface is going to require the ViewModel to have state that does not belong in the model so I believe that there is no such thing as a "stateless" ViewModel in MVVM.

Some examples:

  • Enabled/Disabled state of user interface controls
  • Selected items (listboxes, radio buttons, etc)
  • Input data that has not yet been validated or committed to the model
  • you can have multiple models, which can store those information. For example I have a settingsModel for the state of the checkboxes in my app. Makes it quite easy to store all the settings in a json or other stuff. – Blechdose Nov 12 '19 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.