Android Basic MVVM design pattern

In this tutorial, we are going to learn about the MVVM architecture in Android, and then we will build a project with MVVM design pattern. This tutorial is for android app developer who want to get started with the MVVM architecture. Let's get started MVVM design pattern .

Advantages of Using Clean Architecture
  • Your code is even more easily testable than with plain MVVM.
  • Your code is further decoupled (the biggest advantage.)
  • The package structure is even easier to navigate.
  • The project is even easier to maintain.
  • Your team can add new features even more quickly.
What is MVVM architecture?
  • MVVM architecture is a Model-View-ViewModel architecture that removes the tight coupling between each component. 
  • Most importantly, in this architecture, the children don't have the direct reference to the parent, they only have the reference by observables.
  • It represents the data and the business logic of the Android Application. 
  • It consists of the business logic - local and remote data source, model classes, repository.
  • It consists of the UI Code(Activity, Fragment), XML. 
  • It sends the user action to the ViewModel but does not get the response back directly. To get the response, it has to subscribe to the observables which ViewModel exposes to it.
  • It is a bridge between the View and Model(business logic). 
  • It does not have any clue which View has to use it as it does not have a direct reference to the View. 
  • So basically, the ViewModel should not be aware of the view who is interacting with. It interacts with the Model and exposes the observable that can be observed by the View.

Let us try simple android project with MVVM to load image using Picasso library : Source code