Write cleaner, maintainable, and testable code in Android with MVVM


Published on

Slide deck from YOW Connected 2014 talk
"Write cleaner, maintainable and testable code in Android using Model-View-ViewModel (MVVM)"

Published in: Software

Write cleaner, maintainable, and testable code in Android with MVVM

  1. 1. Write => Cleaner, Maintainable & Testable{ Code } in Android with Model View View-Model (MVVM) YOW Connected 2014Adil MughalSenior Developer @ Nintex
  2. 2. What to Expect Today? •What you must already know? –Android Development –Knowledge of patterns like MVC, MVP, MVVM •What you will see? –How to implement MVVM in Android –HOW than WHY •RoboBinding •Java PropertyChangeListeners
  3. 3. The App
  4. 4. Traditional Way
  5. 5. The Challenges •Complex Activities –UI Logic –GUI Widgets contains state of UI –Communication with outside world •Poor Testability –Testing UI state and Behavior becomes challenging
  6. 6. The MVVM Way
  7. 7. MVVM Quick Intro Model ViewModel View Data-Binding Listeners XML + Activity Presentation Logic Business/Data The objective here is to pull out the state and behavior of the view into a class -State + Behavior -Interaction with Business/External -Maps ViewModelto actual UI widgets
  8. 8. The MVVM Way
  9. 9. The Benefits •View is just UI –Activities/View will just do real UI stuff –Maps the state/behavior to UI Widgets •Improved testability –Having POJO ViewModelhelp testing/mocking easy –Easily test UI logic as simple JUnittest •Relatively easy to follow SOLID principles –Single Responsility, Dependency Injection in ViewModeletc.
  10. 10. Any Questions?
  11. 11. Questions? Thank YOU for your time and attention! Adil Ahmed Mughal @adilamughal http://www.adilmughal.com adil.mughal@live.com http://adilmughal.github.io/YOW2014-Android-MVVM/