Model View ViewModel Android (MVVM)

What is Model View ViewModel Android Design Architecture Pattern? Hey, guys welcome to Techpass Master, In this post, we’ll know about MVVM. MVVM stands for Model View ViewModel. It is an architecture pattern that helps us to structure our project and building robust, maintain testable apps.

Model View ViewModel Android

(MVVM Design Architecture Pattern)

MVVM design pattern helps to separate your view from your business logic, business logic is the core logic of your app and the view should not contain any business logic, it’s only your job to show your views on the screen and manipulate them. MVVM helps us to achieve separation of concern.

Let’s see.

M

V

VM

Model

View

ViewModel

Model

The model contains the data of your app and the logic to access that data. ViewModel works with the model to save and retrieve data.

It contains the following:

  • Model Classes
  • Repository
  • 1) Local (Room and SQLite Database ) and 2) Remote (Web service (Ex. Retrofit))

View

The View Simply represents the UI (Activity, Fragment, XML) of the application. It’s only a job to update the UI by using data from ViewModel to get the data from ViewModel, it has to subscribe to the observer exposed by the ViewModel.

ViewModel

ViewModel is the overpass or way between the view and the Model. ViewModel communicates with the Repository and has the business logic of the view. It interacts with the model and exposes the observer that can be observed by the view that usually are Live Data or the Flow.

Why do we need MVVM?

MVVM makes our app scalable, testable, and understandable. It’s much easier to change the view without losing with the rest of the code and it helps in better separation of concern.

Advantages of MVVM Design Architecture Pattern

  • Its helps to structure our project and building robust, maintain testable apps
  • Every module is independent which improves the testability of every layer.
  • Makes project files maintainable.
  • Enhance the reusability of code.
  • Better Separation of Concerns.
  • and more.

Disadvantages of MVVM Design Architecture Pattern

  • This design pattern isn’t ideal for little projects.
  • Debug is going to be a touch harder.
  • Data-binding logic is just too complex.
Recommended Reading:

I hope you understand the concept of the Model View ViewModel Design Architecture Pattern, if you liked the post so please share the post with other developers. If you have any questions regarding this post. Feel free to comment.

Happy Learning!!!

Leave a Reply