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

Trends & Patterns

Trends & Patterns

Talk given at CocoaHeads Strasbourg.

Frédéric Maquin

November 17, 2016
Tweet

More Decks by Frédéric Maquin

Other Decks in Programming

Transcript

  1. — Christian Tietze Don’t force any architectural patterns down your

    throat. Strive for higher testability first. “ ” 13
  2. single responsability principle class UIViewController: CBCentralManagerDelegate, CLLocationManagerDelegate { var bluetoothManager:

    CBCentralManager! var locationManager: CLLocationManager! func viewDidLoad() { bluetoothManager.delegate = self locationManager.delegate = self } } 17
  3. Loose coupling allows you to test modules independently from each

    other. Use dependency injection to decouple modules. 20
  4. class Model☰ { let electricalMotor: ElectricalMotor init(electricalMotor: ElectricalMotor) { self.electricalMotor

    = electricalMotor } } class Model☰ViewController { var electricalMotor: ElectricalMotor! } CONSTRUCTOR METHOD with dependency injection 23
  5. class Model☰ { let electricalMotor: ElectricalMotor = Injector.resolve(ElectricalMotor.self) } #

    BAD! ⚠ Inversion of Control is important! with dependency injection 24
  6. What about decoupling the app flow? performSegueWithIdentifier("startCar", sender: self) STORYBOARD

    pushViewController(CarStarter(), animated: true) presentViewController(CarStarter(), animated: true, completion: nil) OLD FASHIONED WAY 26
  7. coordinator APP COORDINATOR AUTHENTICATION COORDINATOR FEED COORDINATOR […] AUTHENTICATION VIEW

    CONTROLLER PROFILE VIEW CONTROLLER FEED VIEW CONTROLLER DETAIL VIEW CONTROLLER 32
  8. Rule of % Very simple app App with a lot

    of UI states and asynchronous behaviors Very complex app built with a large team MVC MVVM VIPER 34 Not meant to be taken as a hard rule.
  9. Don’t try too hard to pick a fitting pattern. Try

    harder to keep the code clear, testable and maintainable, because… 35
  10. — Christian Tietze You need knowledge and experience and creativity.

    When you can come up with something on your own, you can interpret the rules of VIPER, layered architecture, or whatever else you find on the web properly. You can pick up new ideas and come up with solutions on your own instead of looking for a fitting solution out there. “ ” 36
  11. 38 resources iOS Architecture Patterns @borlov MVVM is Not Very

    Good @khanlou MVVM is Exceptionally OK @ashfurrow MVVM Is Quite Okay at What It Is Supposed to Do @ctietze Let’s Play: Refactor the Mega-Controller @andy_matuschak
  12. 39 resources Coordinators Redux @khanlou Improve your iOS Architecture with

    FlowControllers @merowing Coordinators with Storyboards @apokrupto