Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MVVM with DataBinding on android

347 views

Published on

Simple presentation about MVVM with DataBinding on Android.

Published in: Software
  • Be the first to comment

MVVM with DataBinding on android

  1. 1. MVVM + Data Binding on Android Made (with love) by Rodrigo Bresan
  2. 2. What is MVVM? - Architectural pattern (such as MVC, MVP, VIPER, etc) - Decouple business logic from user interface - Model (data) - View (UI) - ViewModel (logic and state) Data binding Activities/Fragments/XML Presentation logic - State + Behaviour - Interaction with Busines/External Business/Data
  3. 3. Why use it? - Decouple business logic from user interface - Abstract Android APIs from business logic - Better testability - Follows SOLID principles
  4. 4. Traditional way - Single activity with many responsibilities: - Handling state and behaviour of screen (UI widgets); - Communicating with external world (models); - Testing becomes harder, due to high being coupled with Android APIs
  5. 5. Layers - View - just UI (components) that displays the data to user - Model - Well, data :-) - ViewModel - Logic that should be applied on data for being presented (raw data to friendly) - Usage of Observable pattern
  6. 6. View - Working with Android APIs; - Initializing/Destroying activities; - Handling toasts, snackbars, dialogs, menus; - Handling permissions;
  7. 7. View Model - Handling view states (no connection, empty content, load content) - Visibility - Received extras and arguments - Input validations - Fetching data from model - Uses the application context (since we would use the activity context only for showing dialogs, starting activities and inflating layouts)
  8. 8. Model - Anything that can provides information: - REST APIs (Retrofit) - Local storage (Realm, DBFlow, SQLite) - Shared Preferences - Firebase - Sensor Manager - Geolocation
  9. 9. Testing - Model and ViewModel can be tested with simple JUnit Tests (mocking with Mockito), since they don't rely on Android APIs - View can be tested using Espresso, doing only UI assertions, since all the logic is being tested on the ViewModel layer
  10. 10. A picture piece of code is worth a thousand words https://github.com/bresan/GitHubMVVM

×