Getting started with MVVM
MVVM allows you to separate the UI and business logic. When you need to redesign the UI or update the Model/business logic, you only need to touch the relevant component without affecting the other components of your app. This will make it easier for you to add new features and test your existing code. MVVM is also useful in creating huge applications that use a lot of data and views.
With the MVVM architectural pattern, your application will be grouped into three components:
- Model: This represents the data layer
- View: This is the UI that displays the data
- ViewModel: This fetches data from
Model
and provides it toView
The MVVM architectural pattern can be understood better through the following diagram:
Figure 15.1 – The MVVM architectural pattern
The Model contains the data of the application. The activities, fragments, and layouts that your users see and interact with are the Views in MVVM....