MVVM Architectural Pattern

way to structure code

the Model-View-ViewModel Pattern helps to cleanly separate the business and presentation logic of an application from its user interface (UI) Activities/ Fragments.

MVVM Consists of three core components: the model, the view and the view model

Model

holds the application data which might come from your API’s or other sources such as SQLite files, etc.

View

Is responsible for what the user sees on the screen, it displays visual elements and controls on the screen. They’re typically subclasses of UIView

ViewModel

ViewModel interacts with model and also prepares observable(s) that can be observed by a View. ViewModel can optionally provide hooks for the view to pass events to the model.
One of the important implementation strategies of this layer is to decouple it from the View, i.e, ViewModel should not be aware about the view who is interacting with.

Benefits of using MVVM

  • Life Cycle state of the app will be Maintained
  • the app will be in the same position the same exact state as when the user left it.