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.

Model-View-ViewModel and RxJava

518 views

Published on

Since the Model-View-Presenter pattern and RxJava have been adopted more and more in the Android community, the Model-View-ViewModel pattern emerged as a natural extension combining the benefits of these two concepts.
Simple code snippets will be used to explain MVVM implementation and testing and showcase the advantages over MVP. Engineering war stories along with our lessons learned will be shared so you can avoid the mistakes we have made. I will also give you our answer for: is Rx a remedy for all ills and difficulties in every codebase or can the medicine have unforeseen adverse effects?

Simple MVVM example: https://github.com/florina-muntenescu/DroidconMVVM
MVP vs MVVM example: https://github.com/florina-muntenescu/MVPvsMVVM

Published in: Software
  • Be the first to comment

Model-View-ViewModel and RxJava

  1. 1. 1 MVVM and RxJava – the perfect mix Florina Muntenescu GDG Android Berlin
  2. 2. 2 What and who upday is
  3. 3. 3 When did we decide to go the RxJava & MVVM way?
  4. 4. 4 The old app When did we decide to go the RxJava & MVVM way?
  5. 5. 5 The old app When did we decide to go the RxJava & MVVM way? 99 little bugs in the code. 99 little bugs in the code. Take one down, patch it around. 127 little bugs in the code…
  6. 6. 6 From the old to the new When did we decide to go the RxJava & MVVM way?
  7. 7. 7 Crash course in RxJava
  8. 8. 8 Sum it up! Crash course in RxJava A1 0 A2 2 C1 3 combineLatest( (A1,A2) => A1+A2) 0 0 1 1
  9. 9. 9 What is MVVM and how do you apply it?
  10. 10. 10 Model-View-Presenter What is MVVM and how do you apply it? ModelView Presenter IView IPresenter 1 … 1
  11. 11. 11 Model-View-ViewModel What is MVVM and how do you apply it? DataModelView ViewModel 1 … *
  12. 12. 12 What is MVVM and how do you apply it?
  13. 13. 13 Model-View-ViewModel What is MVVM and how do you apply it? DataModelView ViewModel 1 … *
  14. 14. 14 Testing What is MVVM and how do you apply it?
  15. 15. 15 Model-View-ViewModel What is MVVM and how do you apply it? DataModel 1 … * View ViewModel 1 … * View ViewModel 1 … * View ViewModel 1 … * View ViewModel
  16. 16. 16 What is MVVM and how do you apply it? 1 … * Function View Function ViewModel1 … *Spreadsheet View Spreadsheet ViewModelObservable<String> getFunctionText()
  17. 17. 17 What is MVVM and how do you apply it? 1 … 1 Function View implements IFunctionView Function Presenter1 … 1Spreadsheet View Spreadsheet Presenter implements IFunctionView void textUpdated(String)
  18. 18. 18
  19. 19. 19 We made mistakes but we recovered!
  20. 20. 20 We made mistakes but we recovered!
  21. 21. 21 View We made mistakes but we recovered!
  22. 22. 22 View We made mistakes but we recovered!
  23. 23. 23 ViewModel We made mistakes but we recovered!
  24. 24. 24 Testing the ViewModel – positive case We made mistakes but we recovered!
  25. 25. 25 Testing the ViewModel – negative case We made mistakes but we recovered!
  26. 26. 26 View We made mistakes but we recovered!
  27. 27. 27 We made mistakes but we recovered! What about Views that don’t have have lifecycle events?
  28. 28. 28 We made mistakes but we recovered! Views and subscriptions
  29. 29. 29 We made mistakes but we recovered! Views and subscriptions
  30. 30. 30
  31. 31. 31 RxJava – the good and the bad
  32. 32. 32 RxJava – the good and the bad RxJava vs Threads/AsyncTask/Event bus frameworks
  33. 33. 33 Stream composability FTW! RxJava – the good and the bad
  34. 34. 34 Split a string using a regular expression and append a new line to each item in the resulting list RxJava – the good and the bad “RxJava – the good and the bad” [“RxJavan”, “then”, “goodn”, ”andn”, “then”, ”badn”]
  35. 35. 35 RxJava – the good and the bad map(line -> line.trim() + NEW_LINE) toList() “RxJava“ … “the“ “good“ “RxJavan “ … “then“ “goodn“ ["RxJavan“, “then“, “goodn“ ...]
  36. 36. 36 Split a string using a regular expression and append a new line to each item in the resulting list RxJava – the good and the bad
  37. 37. 37
  38. 38. 3838 Simple MVVM example: https://github.com/florina-muntenescu/DroidconMVVM MVP vs MVVM example: https://github.com/florina-muntenescu/MVPvsMVVM upday tech blog: https://upday.github.io/ Exclusive to Samsung

×