×
KODE CREATORS
10 May 2019

What is MVVM (Model View ViewModel) Architecture ?

MVVM stands for Model View View-model it provides the separation of development of the graphical user interface(GUI) from the business logic or back-end logic (or data model).

Top Android App Devlopment Company in India

The view model of MVVM is a converter that converts the data from the model in such a way that it can be managed and presented with great ease. So we could say that the view model is more model rather than a view as it handles most of the view's logic and it even makes the code very readable.

The Architectural components of MVVM are:-

Live Data

It is a data holder class. Unlike regular observables, it is aware of the lifecycle components and it strictly respects those components such as activities, fragments, or services. This awareness ensures that LiveData only updates the components that exist in the lifecycle state.

Repository

The repository handles all the data operations. It is a clean way to provide explicit distinctions between data retrieval and data display.

Repositories are well aware of the location of the data and what API calls to make when the data is updated. So in simple words, repositories are mediators between different data sources, such as models, web services, and caches.

ViewModel

ViewModels are simples classes that interact with the business logic and data and actually have no idea about the consumer of data. Only View(Activity) holds the reference to ViewModel.

Room

It provides a layer over SQLite to ease database access while harnessing the full functionality of SQLite

Advantages of MVVM:-

Ease of Maintainance

MVVM facilitates the separation of code in an easy manner which makes it very easy to make changes in the code without worrying. That means you can remain agile and can roll out new releases very quickly.

Efficient Testing

With MVVM each piece of code is more specific and if it is implemented in the correct manner then it makes it extremely simple to unit test as the business logic and data are in different locations.