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

Fancy Acronyms for Fancy Architectures

Fancy Acronyms for Fancy Architectures

An introduction to MVC, MVVM, and VIPER architectures for the iOS platform.

katfishi

May 08, 2015
Tweet

More Decks by katfishi

Other Decks in Technology

Transcript

  1. • View operations • View sizing • View rotation •

    iPhone / iPad support • Table cell configuration • Title updates • User interaction processing • Network operations • Reachability calls • Data refresh • Data fetch • Download processing • Tons and tons of video logic • URL processing • Adding / removing player • Caching • Next / previous video • Subtitles • etc.
  2. SOME PRESUMPTIONS • Testing is good • Reduces bugs and

    crashes • Rewriting code / duplicating code is bad • Easy to miss something • Abstracting functionality (and therefore writing more code initially) could be worth it if it improves testing and minimizes future rewrites
  3. DOGGY LIFE APP • Bone-finder for the yard • Activity

    alarm • Human detector • Car detector • Squirrel detector • …and more
  4. DOGGY LIFE APP • Bone-finder for the yard • Activity

    alarm • Human detector • Car detector • Squirrel detector • …and more
  5. SUPER DUPER BONE FINDER • class Bone • id of

    bone (unique per hole) • type of bone (string) • provides a way to retrieve data objects Controller View Model
  6. SUPER DUPER BONE FINDER • class Hole • id of

    hole (unique per hole) • bones inside of hole (array of bone ids) • location within the yard (latitude and longitude) • provides a way to retrieve data objects Controller View Model
  7. SUPER DUPER BONE FINDER • class BoneFinderController • fetches holes

    and associated bones • passes data along to view when needed • navigates between list of holes and bones • resizes view Controller View Model
  8. SUPER DUPER BONE FINDER • class BoneFinderTableView • displays the

    table of holes & bones • passes any user interaction to controller Controller View Model
  9. MOAR FEATURES! • Dowsing phone — rings when near a

    hole • Track hole count • Track most recently buried bones Controller now has to manage all of these
  10. OVERLOADED CONTROLLER • class BoneFinderController • fetches holes and associated

    bones • passes data along to view when needed • navigates between list of holes and bones • resizes view Controller View Model
  11. OVERLOADED CONTROLLER • class BoneFinderController • fetches holes and associated

    bones • tracks most recently buried bone • fetches number of holes • rings when coordinates and current location match • passes formatted data along to view when needed • navigates between list of holes and bones • resizes views
  12. OVERLOADED CONTINUED • class BoneFinderController • data manipulation functions •

    fetches holes and associated bones • tracks most recently buried bone • fetches number of holes • rings when coordinates and current location match • passes formatted data along to view when needed
  13. • class BoneFinderViewModel • fetches and formats necessary data from

    model • most recently buried bone • count of holes • passes this data to the view MVVM VM V C M Nav V C
  14. • class Bone • id of bone (unique per hole)

    • type of bone (string) • provides a way to retrieve data objects MVVM VM V C M Nav V C
  15. • class Hole • id of hole (unique per hole)

    • bones inside of hole (array of bone ids) • location within the yard (latitude and longitude) • provides a way to retrieve data objects MVVM VM V C M Nav V C
  16. DOGGY LIFE APP • Bone-finder for the yard • Activity

    alarm • Human detector • Car detector • Squirrel detector • …and more
  17. DOGGY LIFE APP • Bone-finder for the yard • Activity

    alarm • Human detector • Car detector • Squirrel detector • …and more
  18. DOGGY LIFE APP • Bone-finder for the yard • Activity

    alarm • Human detector • Car detector • Squirrel detector • …and more
  19. HELPFUL FRIENDS What if I want to work with my

    friends (or co- workers) on a large-scale app? That’s always caused mayhem before…
  20. A SIMPLE TAP Model Interactor V C Presenter Wireframe Presenter

    passes data-related action to interactor
  21. BONE FINDER 3.0 • class Bone • id of bone

    (unique per hole) • type of bone (string) • provides a way to retrieve data objects M I V C P WF
  22. • class Hole • id of hole (unique per hole)

    • bones inside of hole (array of bone ids) • location within the yard (latitude and longitude) • provides a way to retrieve data objects BONE FINDER 3.0 M I V C P WF
  23. • class BoneFinderInteractor • fetches necessary data from model •

    takes data and creates simple data structures • passes these data structures to the presenter BONE FINDER 3.0 M I V C P WF
  24. • class BoneFinderPresenter • takes data structures given to it

    by interactor and formats it for the view • immediate handler for user interaction • passes along requests when needed BONE FINDER 3.0 M I V C P WF
  25. • class BoneFinderWireframe • presents other view controllers when needed

    • navigates away from current presenter when called on • could lead to completely other module, such as activity alarm BONE FINDER 3.0 M I V C P WF
  26. • class BoneViewController • displays formatted data from presenter •

    passes any user interaction to presenter BONE FINDER 3.0 M I V C P WF
  27. HELPFUL FRIENDS • Annabelle’s friends can create their own modules

    in any format • As long as they follow a specific protocol • Annabelle can then integrate each module as if it were a view controller • VIPER has the advantage of not needing to peer into other modules to connect code (because of the nice separation of concerns)
  28. TAKEAWAYS • MVC - model view controller • great, lightweight

    architecture with minimal setup overhead • if your app is simple and your testing is fine, you can stick with this • MVVM - model view view model • if your view controllers became massive, good to switch to this • testing is easier than keeping your view controllers massive
  29. TAKEAWAYS • VIPER - view interactor presenter entity routing •

    if your app is highly collaborative and composed of many parts, good to switch to this • testing is easy too, and the isolation of modules is worth the setup if that was your goal
  30. RESOURCES • Apple Developer Guide - MVC • Ray Wenderlich

    - iOS Design Patterns by Eli Ganem • Objc - Introduction to MVVM by Ash Furrow • Mutual Mobile - Introduction to VIPER by Jeff Gilbert • Objc - Architecting iOS Apps with VIPER by Jeff Gilbert and Conrad Stoll