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.

Choosing the architecture

491 views

Published on

Palestra apresentada no TDC Florianópolis 2016

Published in: Software
  • Be the first to comment

  • Be the first to like this

Choosing the architecture

  1. 1. CHOOSING THE ARCHITECTURE FROM MV(X) TO VIP(ER) 1
  2. 2. ABOUT US Giovane Berny Possebon Mobile Developer giovane.possebon@ilegra.com Lucas Dutra Fonseca Mobile Developer lucas.fonseca@ilegra.com
  3. 3. WHY CARE ABOUT IT? 3
  4. 4. "BECAUSE IF YOU DON’T, ONE DAY, DEBUGGING A HUGE CLASS WITH DOZENS DIFFERENT THINGS, YOU’LL FIND YOURSELF BEING UNABLE TO FIND AND FIX ANY BUGS IN YOUR CLASS." Someone who’s right WHY CARE ABOUT IT? 4
  5. 5. WHY CARE ABOUT IT? REASONS ▸ This class is the UIViewController subclass. ▸ Your data is stored directly in the UIViewController ▸ Your UIViews do almost nothing ▸ The Model is a dumb data structure ▸ Your Unit Tests cover nothing 5
  6. 6. WHY CARE ABOUT IT? SO WHAT A GOOD ARCHITECTURE SHOULD HAVE? ▸ Balanced distribution of responsibilities among entities with strict roles. ▸ Testability usually comes from the first feature. ▸ Ease of use and a low maintenance cost. 6
  7. 7. THEN SHOW ME THESE ARCHITECTURES! 7
  8. 8. THEN SHOW ME THESE ARCHITECTURES! RENOWNED ARCHITECTURES ▸ MVC ▸ MVP ▸ MVVM ▸ VIPER ▸ VIP 8
  9. 9. MVC MODEL-VIEW- CONTROLLER 9
  10. 10. MVC - MODEL-VIEW-CONTROLLER HOW IT SHOULD BE VIEW CONTROLLER MODEL Updates NotifiesSend actions 10
  11. 11. MVC - MODEL-VIEW-CONTROLLER HOW IT REALLY IS VIEW CONTROLLER MODEL Owns and updates Notifies 11
  12. 12. MVC - MODEL-VIEW-CONTROLLER HOW IT REALLY IS VIEW CONTROLLER MODEL Owns and updates Notifies MVC 12
  13. 13. MVC - MODEL-VIEW-CONTROLLER HOW IT REALLY IS VIEW CONTROLLER MODEL Owns and updates Notifies Massive View Controller 13
  14. 14. MVC - MODEL-VIEW-CONTROLLER CONCLUSION ▸ Distribution of Responsibilities - View and controller tightly coupled ▸ Testability - Only model is testable ▸ Ease of Use - Low amount of code. Everyone is familiar with it. 14
  15. 15. MVP MODEL-VIEW-PRESENTER 15
  16. 16. What if I told you, the UIViewController is the View.
  17. 17. MVP - MODEL-VIEW-PRESENTER MVC IN THE RIGHT WAY PASSIVE VIEW PRESENTER MODELUpdates Owns and updatesOwns and send actions Notifies 17
  18. 18. MVP - MODEL-VIEW-PRESENTER MVC IN THE RIGHT WAY PASSIVE VIEW PRESENTER MODELUpdates Owns and updatesOwns and send actions Notifies UIViewController UIKit independent mediator 18
  19. 19. MVP - MODEL-VIEW-PRESENTER CONCLUSION ▸ Distribution of Responsibilities - Most of responsibilities divided between the Presenter and the Model, with the pretty dumb View ▸ Testability - Good, we can test most of the business logic due to the dumb View ▸ Ease of Use - Substantial amount of code, although idea is very clear 19
  20. 20. MVVM MODEL-VIEW-VIEWMODEL 20
  21. 21. MVVM - MODEL-VIEW-VIEWMODEL THE GREATEST OF THE MV(X) KIND VIEW VIEWMODEL MODELUpdates Owns and updatesOwns and send actions Notifies 21
  22. 22. MVVM - MODEL-VIEW-VIEWMODEL CONCLUSION ▸ Distribution of Responsibilities - Similar to MVP, but View has more responsibilities than the MVP’s ▸ Testability - View Model knows nothing about the View, this allows us to test it easily. The View might be also tested ▸ Ease of Use - It has almost the same amount of code as the MVP 22
  23. 23. VIPER 23
  24. 24. VIPER THE LEGO ARCHITECTURE VIEW PRESENTER ENTITY Updates Owns and asks for updatesOwns and send actions Notifies INTERACTOR ROUTER Knows about 24
  25. 25. VIPER THE LEGO ARCHITECTURE VIEW PRESENTER ENTITY Updates Owns and asks for updatesOwns and send actions Notifies INTERACTOR ROUTER Knows about Manipulates data and use cases UIKit independent mediator Former Model 25
  26. 26. VIPER CONCLUSION ▸ Distribution of Responsibilities - VIPER is a champion in distribution of responsibilities. ▸ Testability - better distribution — better testability ▸ Ease of Use - You have to write huge amount of interface for classes with very small responsibilities. 26
  27. 27. VIP CLEAN SWIFT 27
  28. 28. VIP THE CLEAN ARCHITECTURE VIEW PRESENTER ENTITY Updates Process and deliver dataSend actions INTERACTOR ROUTER Knows about Owns 28
  29. 29. VIP THE CLEAN ARCHITECTURE VIEW PRESENTER ENTITY Updates Process and deliver dataSend actions INTERACTOR ROUTER Knows about Owns UIKit independent mediator Former Model 29
  30. 30. VIP CONCLUSION ▸ Distribution of Responsibilities - VIP is as good as VIPER in terms of distribution of responsibilities. ▸ Testability - Also comparable to VIPER ▸ Ease of Use - Great amount of classes with very small responsibilities, but clearer than VIPER 30
  31. 31. CHOOSING THE ARCHITECTURE REFERENCES ▸ https://medium.com/ios-os-x-development/ios- architecture-patterns-ecba4c38de52 ▸ http://clean-swift.com/clean-swift-ios-architecture/ 31
  32. 32. CHOOSING THE ARCHITECTURE CODE REPOSITORY ▸ https://github.com/lfonseca/choosing-the-architecture 32
  33. 33. THANKS! Giovane Berny Possebon Mobile Developer giovane.possebon@ilegra.com Lucas Dutra Fonseca Mobile Developer lucas.fonseca@ilegra.com
  34. 34. EXPERIENCES SO FAR… 34

×