Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android's ViewModel and MVVM

Tags:

android

mvvm

There is a design pattern called MVVM (Model-View-View Model), in which a View Model is used as an abstraction of a View. The View Model supposed to expose streams of data to the View and interact with Model's data.

However there is a ViewModel class in Android's framework.


Question: does Android's ViewModel have something to do with the View Model from MVVM pattern?

like image 822
0leg Avatar asked Nov 07 '22 21:11

0leg


1 Answers

They are different. The ViewModel that Android is referring to is just.

The ViewModel class is designed to store and manage UI-related data so that the data survives configuration changes such as screen rotations.

The MVVM pattern will require a View, ViewModel and Model. With binding occurring between the View and ViewModel.

The Android ViewModel interacts with the UIController, and is almost just a state hold for UI, rather than following the MVVM pattern.

like image 182
Adam Avatar answered Nov 15 '22 11:11

Adam