0

(This question applies equally to MVC and other patterns but I'm currently working on an MVVM based app.)

In the MVVM pattern; the View acts directly on the ViewModel which, in turn, acts directly on the Model which notifies the ViewModel to which the View is bound. Thus a change request propagates from a View to the Model and returns as an update to the View.

Why wouldn't you do the following? View issues a change request notification. ViewModel receives the notification and issues its own change request notification. The Model receives the notification, changes and issues a changed notification. ViewModel receives this and issues its own changed notification. View receives this and updates.

It sounds more complicated (four notifications per change) but achieves 100% separation of layers and permits any number of Models to be connected to the View (and vice versa).

Note: The same question applies if you substitute RxSwift or other mechanisms in place of notifications.

Vince O'Sullivan
  • 2,611
  • 32
  • 45

1 Answers1

0

What you're saying is completely true. (and it's not complicated at all).

Acting on Model change, is basically talking about the dependencies your Model has one different Modules. (such as fetching Contacts from device, or a push received by the server or ...). That's what this behavior is trying to describe, on the other hand, what you're saying is describing the behavior of User triggered actions (such as reload, button taps or ...).

On the other hand, it depends on how you approach implementing ViewModel. since there's no rule of thumbs for implementing ViewModel, each team or person implements it differently. Some implement the whole Logic inside the ViewModel and Model is as dumb as possible. Some implement ViewModel as dumb as possible which only connects View to the Model and vice versa.

I Myself, usually implement ViewModel as the Logic, and Model as dumb as possible and apply my separations on composition. (one ViewModel might connect to different ViewModels and ...).

I can easily connect my ViewModels to a CI and my project would still work. (hence I can write Unit-Tests, UI-Tests, Integration tests for all of them)

farzadshbfn
  • 2,710
  • 1
  • 18
  • 38