The Movie Database implementation using Model-View-ViewModel architecture with dagger2 & rxjava
MVVM is one of the architectural patterns which enhances separation of concerns, it allows separating the user interface logic from the business (or the back-end) logic. Its target (with other MVC patterns goal) is to achieve the following principle “Keeping UI code simple and free of app logic in order to make it easier to manage”.
The main players in the MVVM pattern are:
- Model - Model represents the data and business logic of the app. One of the recommended implementation strategies of this layer, is to expose its data through observables to be decoupled completely from ViewModel or any other observer/consumer.
- 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.
- View - Finally, the view role in this pattern is to observe (or subscribe to) a ViewModel observable to get data in order to update UI elements accordingly.
The following diagram shows MVVM components and basic interactions.
Sample | Description |
---|---|
mvvm-rxjava | Demonstrates a basic Model‑View‑ViewModel architecture with Data Binding library. This sample uses RxJava 2 to implement concurrency, and abstract the data layer. |
mvvm-livedata | Demonstrates a basic Model‑View‑ViewModel architecture with Data Binding library. This sample uses Live data. |
Sample | Description |
---|---|
mvvm-kotlin | Conversion of mvvm-livedata to Kotlin |
Download the example app here.