MVVM pattern

MVVM is architectural pattern that separates an application into three main logical components Model, View, and ViewModel.

It is a derivation of the MVC pattern, in which Controller is replaced with ViewModel.

Model is responsible to manage data, that independent from the user interface. It is recommended to expose data through observables, for example with RxJava library.

View is responsible for rendering UI elements, accept user input and pass it to the ViewModel. View does not know anything about Model. It interacts only with ViewModel.

ViewModel is responsible for interaction with Model and also prepares observable(s) that can be observed by a View.

Read more how to implement MVVM in Android.

advantages

1. Ensures your UI matches your data state.

2. No memory leaks. Observers are bound to lifecycle of View and clean up after themselves when their associated lifecycle is destroyed.

3. No crashes due to lifecycle stopped.

MVP vs MVVM

In MVP Presenter provides set of data, that View uses.

In MVVM View observes data of ViewModel, in other words synchronizes with data. So MVVM more event driven. Unlike Presenter, ViewModel does not contain reference to the View (otherwise a memory leak may occur).