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.

iOS advanced architecture workshop 3h edition

230 views

Published on

The 3h workshop version of the 3d Advanced Architectures training (http://canonicalexamples.com/courses_ios/#iOSArch). I have delivered this one or the Android counterpart in more than 20 cities in Europe and America. This is version that I shared in Cluj Napoca.

Published in: Software
  • Be the first to comment

iOS advanced architecture workshop 3h edition

  1. 1. #Swift3Arch Implementing Clean Architecture for iOS Jorge D. Ortiz-Fuentes @jdortiz
  2. 2. A Canonical Examples production #Swift3Arch
  3. 3. #Swift3CA Agenda ★ Goals ★ Before Clean Architecture ★ Clean Architecture Concepts ★ Implementation rules ★ Example App: RealProgrammers ★ Implement 1st User Story ★ Connect the pieces ★ References
  4. 4. #Swift3CA Full Version: 3d ★ MVX • Learn • Extract MVP ★ 1st User Story • Use Case • Presenter • View • Entity Gateway • Initial connection ★ Connectors • Memory Management • Reuse ★ 2nd user story: add • Navigation: Modal vs Push • Command pattern • Immutables • Observation ★ 3rd user story: detail • Identity • Use case factories • 2nd use case in the same view ★ Other use cases: just logic ★ Forward flow synchronization ★ Dependency Injection ★ Asynchrony • Async entity gateway • Other tasks
  5. 5. #Swift3CA LIVE Online Training ★ 3 days (same weekday 3 continuous weeks) ★ 10 people max ★ Live coding shared via video conference ★ Chat running all the time ★ Complete repo with many commits and Tests> 95% ★ Additional exercises ★ Ask as much as you want!
  6. 6. More info at: http://canonicalexamples.com
  7. 7. Goals
  8. 8. #Swift3CA Goals ★ Understand the concepts ★ Learn the sources ★ Implement the ideas of the Clean Architecture in a real app ★ Grow from here
  9. 9. Looking for volunteers
  10. 10. Warning: Background Ahead!
  11. 11. Before Clean Architecture
  12. 12. #Swift3CA Before Clean Architecture ★ MVC ★ MVP ★ MVVM
  13. 13. – Martin Fowler “Different people reading about MVC in different places take different ideas from it and describe these as 'MVC'. If this doesn't cause enough confusion you then get the effect of misunderstandings of MVC that develop through a system of Chinese whispers.”
  14. 14. #Swift3CA Tricky question ★ If [Model] + [View] + [Controller / Presenter / View Model] = [TheApp] ★ How can Controller != Presenter != View Model? ★ Responsibilities matter! ★ Other components (patterns) might be involved.
  15. 15. #Swift3CA The goal ★ Separation of responsibilities into roles. Is it? Not historically. Other motivations. Solving problem d’jour. ★ Now why? • Testability • Reusability • Extensibility
  16. 16. #Swift3CA MVC: The early days ★ Separated presentation: Model <-> Presentation (= V+C) ★ Observer originated from MVC, but observing full object (properties = scalars) ★ Variations: Passive model, i.e. model cannot send updates (for example HTTP)
  17. 17. #Swift3CA Apple’s MVC Ctrlr ModelView
  18. 18. #Swift3CA MVC: Composite Pattern ★ Composite ★ Strategy ★ Observer
  19. 19. #Swift3CA iOS MVC ★ View • Only UIView subclasses • Show information and handle events to controller • Fully reusable library of views. Consistent L&F ★ Controller • Views delegate+dataSources control what’s displayed • Receive the events and converts them into calls to the model • Observe the model and update what is displayed on the view • Implement presentation logic ★ Model • Implements domain knowledge / business logic. Provides data and commands • Can be observed • No references to the UI Flow synchronization vs Observer synchronization
  20. 20. #Swift3CA MVC: testability ★ The views are somebody else's (Apple’s) problem. ★ Model is easy to test. ★ Controller is huge & has dependencies on the model and on the views => Complex to test. ★ Too many levels of abstraction, only a few methods exposed. ★ Some stuff in view controller that it is usually not tested.
  21. 21. MVP
  22. 22. #Swift3CA MVP Presenter ModelView Events Operations Changes Changes
  23. 23. MVVM
  24. 24. #Swift3CA MVVM View Model ModelView Events & Info Operations Changes Changes
  25. 25. Clean Architecture Concepts
  26. 26. What is missing?
  27. 27. #Swift3CA Clean Architecture ★ Uncle Bob’s (Robert C. Martin’s) architecture ★ Based on Onion, in turn based in hexagonal, DCI and some others
  28. 28. #Swift3CA Clean Architecture: iOS App Delegate View (VC) Presenter Interactor Entity Gateway Connector
  29. 29. #Swift3CA Persistance FW View Network LocationFW Presenter Entity Gateway Clean Architecture Interactor Entity
  30. 30. Implementation Rules
  31. 31. #Swift3CA Rules ★ We are going to develop one module at a time ★ Follow the dependency rules ★ YAGNI ★ No early optimization applied ★ It is easy to add tests, but no TDD in 3h OK??
  32. 32. Example App: RealProgrammers
  33. 33. #Swift3CA Features ★ Add potential candidates (Name and important skills) ★ Show list of candidates with relative interview date ★ Remove candidates from list ★ Edit the data of any candidate ★ Contact candidate by email ★ Sync between devices ★ Universal app ★ Eye candy ★ iOS/macOS/watchOS/tvOS? ★ Credits
  34. 34. #Swift3CA MVP Features ★ Add potential candidates (Name and important skills) ★ Show list of candidates with relative interview date ★ Remove candidates from list ★ Edit the data of any candidate ★ Contact candidate by email ★ Sync between devices ★ Universal app ★ Eye candy ★ iOS/macOS/watchOS/tvOS? ★ Credits
  35. 35. Implementing the 1st User Story
  36. 36. I feel like I could Take On the World!
  37. 37. #Swift3CA First User Story ★ Show a list of data elements to the user.
  38. 38. #Swift3CA Interactor View (VC) Presenter Show
 Programm Entity Gateway
  39. 39. #Swift3CA Interactor ★ Grab data from the entity gateway ★ Convert it to what is needed to be presented ★ Pass the results to the presenter ★ Start by defining the protocols
  40. 40. #Swift3CA Presenter View (VC) Programm ers
 Show
 Programm Entity Gateway
  41. 41. #Swift3CA Presenter ★ Direction: only from interactor to view ★ Configure the (dumb) view with the data provided to it ★ Create the protocol for the view (Simplest wins!)
  42. 42. #Swift3CA View Programm ers Programm ers
 Show
 Programm Entity Gateway
  43. 43. #Swift3CA View ★ Combination of Views + View Controller ★ Make it dumb (passive), but useful ★ Tell the presenter about the relevant events ★ Keep them decoupled
  44. 44. #Swift3CA Presenter Programm ers Programm ers
 Show
 Programm Entity Gateway
  45. 45. #Swift3CA Back to the Presenter ★ Implement responses to the user events. ★ Use the interactor ★ Add presentation logic to the presenter part
  46. 46. #Swift3CA Presentation Logic ★ Date should be relative (“Today”, “1d ago”, “2w ago”) ★ That means current date is a dependency that we want to control for tests ★ Use default value for the current date
  47. 47. #Swift3CA Entity Gateway Programm ers Programm ers
 Show
 Programm Entity Gateway
  48. 48. #Swift3CA Entity Gateway ★ Basic ★ Defer the decision of the persistence framework for later. ★ Implement the minimum functionality in a basic object. ★ Implications of the repository pattern.
  49. 49. References
  50. 50. #Swift3CA References ★ http://martinfowler.com/eaaDev/ uiArchs.html ★ https://blog.8thlight.com/uncle-bob/ 2012/08/13/the-clean-architecture.html ★ https://cleancoders.com/episode/clean- code-episode-7/show
  51. 51. Thank you!
  52. 52. @jdortiz #Swift3Arch

×