Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Good Intentions II: Enemy of the State

Good Intentions II: Enemy of the State

Originally presented at 360iDev in Denver, CO on August 19, 2015

In a world where ViewControllers shoulder the burden of managing ever-changing vagarities of application state logic and complex navigation stacks, one design pattern emerges from the past to lead us toward a better, brighter, and lighter future of app development.

In this sequel to last year’s blockbuster presentation, “Good Intentions: Building Better ViewControllers”, we will revive a venerable programming technique for explicitly defining application behaviors and thereby reducing the responsibilities of our much maligned ViewControllers.

83231ffaec4a72ef96d26526872961ac?s=128

Jay Thrash

August 19, 2015
Tweet

Transcript

  1. Good Intensions 2 Enemy of the State Jay Thrash @jaythrash

    360iDev, Denver August 2015 Intentions
  2. You Survived! 2015

  3. You made it! or did you?

  4. Good Intentions 2 Enemy of the State Jay Thrash @jaythrash

    360iDev, Denver August 2015 “relax”
  5. Intention

  6. Intention “you keep using that word…”

  7. Intention inˈten(t)SH(ə)n/ 1. a thing intended; an aim or plan.

  8. Ambiguity Intention

  9. BE OBVIOUS Intention

  10. Previously, at

  11. Jay Thrash @jaythrash 360iDev, Denver August 2014 A Path to

    Building Better ViewControllers Good Intentions
  12. Jay Thrash @jaythrash 360iDev, Denver August 2014 A Path to

    Building Better ViewControllers Good Intentions Stores Techniques 3 Delegate(v) the DataSources Intentions
  13. State

  14. State Managing with intent

  15. BOOL ENUM & State Managing

  16. BOOL ENUM & Managing state

  17. BOOL ENUM & Managing state ✓Easy to start ‣Minimal states

    ‣Quick to Conflict
  18. BOOL ENUM & Managing state ✓Easy to start ‣Minimal states

    ‣Quick to Conflict ✓No Conflicts ‣From Any, to Any ‣No Rules
  19. Managing state BOOL ENUM & ✓Easy to start ‣Minimal states

    ‣Quick to Conflict ✓No Conflicts ‣From Any, to Any ‣No Rules TOO AMBIGUOUS
  20. State Machines

  21. State Machines ancient art

  22. State Machines ancient art

  23. State Machines ancient art

  24. “A mathematical model of logic. A state machine can be

    in one of a finite number of states. The machine is in only one state at a time; the state it is in at any given time is called the current state.” State Machines abstract
  25. State Machines abstract

  26. States State Machines abstract

  27. State Machines abstract

  28. Current State State Machines abstract

  29. Transitions State Machines abstract

  30. State Machines practical

  31. State Machines  WWDC 2014 Advanced User Interfaces with Collection

    Views Session 232 practical
  32. State Machines AAPLStateMachine practical

  33. State Machines ✓ Simple Configuration ✓ Transition Logic “DSL” ✓

    Conforms to SRP ✓ Facilitates Automated Testing practical
  34. State Machines NSString * const AAPLLoadStateInitial = @"Initial"; NSString *

    const AAPLLoadStateLoadingContent = @"LoadingState"; NSString * const AAPLLoadStateRefreshingContent = @"RefreshingState"; NSString * const AAPLLoadStateContentLoaded = @"LoadedState"; NSString * const AAPLLoadStateNoContent = @"NoContentState"; NSString * const AAPLLoadStateError = @"ErrorState"; ✓Simple Configuration practical States
  35. State Machines self.validTransitions = @{ AAPLLoadStateInitial : @[AAPLLoadStateLoadingContent], AAPLLoadStateLoadingContent :

    @[AAPLLoadStateContentLoaded, AAPLLoadStateNoContent, AAPLLoadStateError], AAPLLoadStateRefreshingContent : @[AAPLLoadStateContentLoaded, AAPLLoadStateNoContent, AAPLLoadStateError], AAPLLoadStateContentLoaded : @[AAPLLoadStateRefreshingContent, AAPLLoadStateNoContent, AAPLLoadStateError], AAPLLoadStateNoContent : @[AAPLLoadStateRefreshingContent, AAPLLoadStateContentLoaded, AAPLLoadStateError], AAPLLoadStateError : @[AAPLLoadStateLoadingContent, AAPLLoadStateRefreshingContent, AAPLLoadStateNoContent, AAPLLoadStateContentLoaded] }; ✓ Simple Configuration practical Transitions
  36. State Machines ✓ Transition Logic “DSL” practical // NSString *

    const AAPLLoadStateLoadingContent=@“LoadingState”; I (void)somethingHappened { self.stateMachine.currentState = AAPLLoadStateLoadingContent; }
  37. State Machines ✓ Transition Logic “DSL” practical // NSString *

    const AAPLLoadStateLoadingContent = @“LoadingState”; I (void)didEnterLoadingState { [self updatePlaceholder:self.placeholderView]; } I (void)didExitLoadingState { [self thatActionOnLeavingLoadingState]; }
  38. State Machines practical AAPLStateMachine AAPLStateMachine Delegate MyClass AAPLStateMachine Delegate •Configure

    & Conform •Request & React •Validate •Initiate
  39. State Machines ✓ Conforms to SRP practical AAPLStateMachine AAPLStateMachine Delegate

    MyClass AAPLStateMachine Delegate •Configure & Conform •Request & React •Validate •Initiate
  40. BE OBVIOUS

  41. State Machines Applied

  42. State Machines Applied •async Data Sources •branching navigation •session management

  43. State Machines Applied: Async Data Source

  44. State Machines Applied: Async Data Source

  45. State Machines Applied: Async Data Source

  46. State Machines Applied: Async Data Source

  47. State Machines Applied: Async Data Source

  48. State Machines Initial Loading Content Content Loaded Refresh Content Error

    No Content Applied: Async Data Source
  49. State Machines Initial Loading Content Content Loaded Refresh Content Error

    No Content Applied: Async Data Source
  50. State Machines Initial Loading Content Content Loaded Refresh Content Error

    No Content Applied: Async Data Source
  51. State Machines Initial Loading Content Content Loaded Refresh Content Error

    No Content Applied: Async Data Source
  52. State Machines Initial Loading Content Content Loaded Refresh Content Error

    No Content Applied: Async Data Source
  53. State Machines Initial Loading Content Content Loaded Refresh Content Error

    No Content Applied: Async Data Source
  54. State Machines Initial Loading Content Content Loaded Refresh Content Error

    No Content Applied: Async Data Source
  55. State Machines Applied: branching navigation

  56. State Machines Applied: branching navigation

  57. State Machines Applied: branching navigation

  58. State Machines Applied: branching navigation Direct

  59. State Machines Applied: branching navigation Direct Indirect

  60. State Machines Applied: branching navigation

  61. State Machines Applied: branching navigation Appointment Request

  62. State Machines Applied: branching navigation Steps Appointment Request

  63. State Machines Applied: branching navigation Steps Next Appointment Request

  64. State Machines Applied: branching navigation Steps Next Embedded VCs Appointment

    Request
  65. State Machines Applied: branching navigation Appointment Request

  66. State Machines Applied: branching navigation Appointment Request

  67. State Machines Applied: branching navigation Appointment Request

  68. State Machines Whom Initial Whom Valid Direct Search Direct Search

    Valid Direct Chosen When Indirect Indirect Valid Direct Reason Direct Reason Valid Indirect Reason Indirect Reason Valid Applied: branching navigation
  69. State Machines Whom Initial Whom Valid Direct Search When Indirect

    Applied: branching navigation
  70. State Machines Whom Initial Whom Valid Direct Search When Indirect

    Applied: branching navigation
  71. State Machines Whom Initial Whom Valid Direct Search When Indirect

    Applied: branching navigation
  72. State Machines Whom Initial Whom Valid Direct Search When Indirect

    Applied: branching navigation
  73. State Machines Whom Initial Whom Valid Direct Search When Indirect

    Applied: branching navigation
  74. State Machines Whom Initial Whom Valid Direct Search When Indirect

    Applied: branching navigation
  75. State Machines Applied: branching navigation Some time later…

  76. State Machines Whom Initial Whom Valid Direct Search Direct Search

    Valid Direct Chosen When Indirect Indirect Valid Direct Reason Direct Reason Valid Indirect Reason Indirect Reason Valid Applied: branching navigation
  77. State Machines Applied: branching navigation Initial When Indirect Indirect Valid

    Indirect Reason Indirect Reason Valid
  78. State Machines Applied: session management

  79. State Machines Applied: session management

  80. State Machines Unauthent- icated Initial Manual PIN/ TouchID Preloading Running

    Expired Applied: session management
  81. State Machines Applied: session management Unauthenti cated Initial Manual PIN/

    TouchID Preloading Running Expired
  82. State Machines Applied: session management Unauthenti cated Initial Manual PIN/

    TouchID Preloading Running Expired
  83. State Machines Applied: session management Unauthenti cated Initial Manual PIN/

    TouchID Preloading Running Expired
  84. State Machines Applied: session management Unauthenti cated Initial Manual PIN/

    TouchID Preloading Running Expired
  85. State Machines Applied: session management Unauthenti cated Initial Manual PIN/

    TouchID Preloading Running Expired
  86. State Machines Applied: session management Unauthenti cated Initial Manual PIN/

    TouchID Preloading Running Expired
  87. State Machines Applied: branching navigation Some time later…

  88. State Machines Unauthent- icated Initial Manual PIN/ TouchID Preloading Running

    Expired Applied: session management
  89. State Machines Unauthent- icated Initial Manual PIN/ TouchID Preloading Running

    Expired Applied: session management Web Token
  90. State Machines Unauthent- icated Initial Manual PIN/ TouchID Preloading Running

    Expired Applied: session management Web Token
  91. State Machines Unauthent- icated Initial Manual PIN/ TouchID Preloading Running

    Expired Applied: session management Web Token
  92. State Machines Unauthent- icated Initial Manual PIN/ TouchID Preloading Running

    Expired Applied: session management Web Token
  93. State Machines Unauthent- icated Initial Manual PIN/ TouchID Preloading Running

    Expired Applied: session management
  94. In Closing

  95. State Manage with intent

  96. Ambiguous

  97. BE OBVIOUS

  98. Next Steps Topics to Google ➡ WWDC 2014, Session 232


    Advanced UI with CollectionViews ➡ Soroush Khanlou 
 khanlou.com
  99. Thanks! @jaythrash jay@jaythrash.com http://jaythrash.com/talks