What is MVVM?

What is MVVM?

MVVM, means Model-View-View-Model, it's the most popular design pattern for android apps.

Why MVVM?

- your code is decoupled and easy to maintain
- code is testable very easily
- other people understand the structure much faster
- data is not reloaded at device rotation

MVVM Structure :

What is MVVM?



The view 

the view represents either an activity or a fragment . in these classes you should only perform ui operations, such as changing texts , showing Toasts or changing colors.

The viewModel

each activity/fragment holds an instance of a view model. the viewModel is used to get the data from the repository and prepare observables (LiveData) for the view

The model 

the model holds the data of you app. often it is represented by an sqlite database implemented with the room persistence library. it syncs the data with the viewModel so the viewModel can sync it with the view.

The remote data source

this represents data that is provided remotely  by an api . for example , this could be an api that provides data about the current weather. typically , this is implemented with Retrofit

the repository

the repository is used as a central place to retrieve the data from the model and the remote data source and redirect it to the viewModel.

Post a Comment

0 Comments