10

I need to clear some of my doubts regarding mvp and mvvm design pattern

1) In mvp and mvvm who updates the view .The presenter/view-model set the data to be displayed in the view or the view retrieve the data from presenter/view-model and display it

2) How both presenter and view-model differ from each other. "The MVVM uses databinding to update the view whereas the presenter uses traditional methods to update the view". Is it?

1 Answers1

11

In MVP, the Presenter holds a reference to a View, usually via interfaces. When the Presenter computes new data, it is him who is responsible to call the right method on the View/Interface to update the UI.

In MVVM, the ViewModel "simply exposes" data (usually via LiveData or Rx) so it can be observed. It is not responsible for who is observing the data, and what is done with it. The view then observes that said data in the ViewModel, and updates its UI when the data changes.

To have a complete understanding of the differences between MVC, MVP and MVVM, I'd suggest to look at https://www.youtube.com/watch?v=QrbhPcbZv0I

NSimon
  • 5,212
  • 2
  • 22
  • 36
  • so in MVP the presenter update the view while in MVVM the view is responsible for updating the view by fetching data from view-model. Am i correct? –  May 06 '18 at 09:41
  • 1
    Well, in both scenarios, the view (Activity, Fragment etc) is responsible for updating the views (setText for example). However, the difference resides in the communication between View and Presenter/ViewModel. Presenter holds a reference to the View, and tells it to update. ViewModel exposes data (so does *not* references the view), and the View decides what to do with the observed data when it changes – NSimon May 06 '18 at 16:05
  • Yeah got it. Any simple example on mvp and mvvm.Like simple person details on both mvvm and mvp pattern –  May 06 '18 at 16:47