MVVM-7: Keep ViewModels as simple as possible. When needed, transfer responsibility to other layers.


Description

Delegating responsibilities from the ViewModels to other layers results into smaller and more understandable ViewModels. It also makes testing the whole architecture easier. Since each component can be tested separately. Instead of asserting that a View needs to behave after a certain retrieval from the model, the model now can be tested independently.

Example

We created a simple MVVM example.

Our MVVM example depicted:

MVVM depicted

The only job of the viewModel is to listen to the Repository. And when new data is emitted, the data is placed in MutableLiveData.

And what the MainActivity has to do is observe this data.

Check this page to view the complete repository.