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.

Android MVVM

1,169 views

Published on

Implementing MVVM design pattern in Android using Data Binding. An easy way to implement clean MVVM and have a testable code.

Published in: Software
  • Be the first to comment

Android MVVM

  1. 1. MVVM Design Pattern How can I implement it on Android
  2. 2. Who I am david.estivariz@24i.com destivar David Estivariz Android developer Clean coding enthusiast MVVM Design Pattern
  3. 3. What I’m going to talk about? Clean code and design patterns, why? Best practices MVP vs MVVM Helping Frameworks or libraries Android MVVM Architecture example MVVM Design Pattern
  4. 4. MVVM Design pattern WHY ??
  5. 5. Why I use a design pattern? Easier to read/understand Easier to scale Easier to test Easier to find and resolve bugs Easier to be applied to any other language (object-oriented) Reduce technical risk And a long etc… MVVM Design Pattern
  6. 6. MVVM Design pattern How do I start?
  7. 7. Escape from spaghetti code! MVVM Design Pattern
  8. 8. Best Practices Choose your naming well Use meaningful names … but don’t state the obvious Write small methods Write methods that only do one thing Encapsulate boolean expressions or overly-complex code Avoid deep nesting Replace constructors with builders (see builder pattern) Use refactoring patterns to fight against legacy MVVM Design Pattern
  9. 9. MVP vs MVVM MVVM Design Pattern View ViewModel Model Data Binding and Commands ViewModel updates the model Send notifications Send notifications View ModelPresenter Presenter updates the model User events Updates Fire events
  10. 10. MVVM Design Pattern
  11. 11. MVVM Design Pattern Butterknife
  12. 12. Butterknife: before & after MVVM Design Pattern
  13. 13. MVVM Design Pattern Dagger
  14. 14. Dagger: before & after MVVM Design Pattern
  15. 15. MVVM Design Pattern Android Binding
  16. 16. MVVM Design Pattern View - xml layout
  17. 17. MVVM Design Pattern View - activity Android Data Binding framework auto generates code Just get Binding object and set params defined at xml Then xml will automatically get data from the view model
  18. 18. MVVM Design Pattern ViewModel
  19. 19. MVVM Design Pattern Model Model mustn’t do anything not related with itself ViewModel will show model changes in the view Simple and clean
  20. 20. MVVM Design Pattern Custom Binding Adapters Using Custom Binding adapters give you more flexibility A binding adapter can use one or more parameters Their responsibility is to perform actions in the views depending in parameters from the model
  21. 21. MVVM Design Pattern Architecture overview
  22. 22. MVVM Design Pattern Package organisation
  23. 23. MVVM Design Pattern Any question?
  24. 24. MVVM Design Pattern

×