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

iOSDevUK 2015: Clean Code through Dependency In...

AppFoundry
September 15, 2015

iOSDevUK 2015: Clean Code through Dependency Injection

This is a 5 minute fast-talk we gave at iOSDevUK 2015.

AppFoundry

September 15, 2015
Tweet

More Decks by AppFoundry

Other Decks in Programming

Transcript

  1. Coding Example Acceptable in 2012 struct SkeumorphicDesigner { func createDesign(requirements:

    Requirements) -> Design { //Draws some boxes with stitches, applies colors //returns Design } } struct ObjectiveCDeveloper { func createApp(requirements: Requirements, design: Design) -> App { //Does some code between [], applies the design using //InterfaceBuilder, returns App }
  2. Coding Example Acceptable in 2012 class AppFactory2012 { private let

    developer:ObjectiveCDeveloper private let designer:SkeumorphicDesigner init() { developer = ObjectiveCDeveloper() designer = SkeumorphicDesigner() } public func createApp(requirements:Requirements) -> App { let design = designer.createDesign(requirements) return developer.createApp(requirements, design: design) } } … let appFactory = AppFactory2012() let app = appFactory.createApp(requirements)
  3. Coding Example Acceptable in 2013 struct FlatDesigner { func createDesign(requirements:

    Requirements) -> Design { //Draws some flat boxes, applies less color, returns Design } } struct ObjectiveCDeveloper { … }
  4. Coding Example Acceptable in 2013 class AppFactory2013 { private let

    developer:ObjectiveCDeveloper private let designer:FlatDesigner init() { developer = ObjectiveCDeveloper() designer = FlatDesigner() } public func createApp(requirements:Requirements) -> App { let design = designer.createDesign(requirements) return developer.createApp(requirements, design: design) } } … let appFactory = AppFactory2013() let app = appFactory.createApp(requirements)
  5. Coding Example Acceptable in now struct SwiftDeveloper { func createApp(requirements:

    Requirements, design: Design) -> App { //Does some code without semi-colons, applies the //design using StoryBoards, returns App } struct FlatDesigner { … }
  6. Coding Example Acceptable in now class AppFactory2014 { private let

    developer:SwiftDeveloper private let designer:FlatDesigner init() { developer = SwiftDeveloper() designer = FlatDesigner() } public func createApp(requirements:Requirements) -> App { let design = designer.createDesign(requirements) return developer.createApp(requirements, design: design) } } … let appFactory = AppFactory2014() let app = appFactory.createApp(requirements)
  7. Coding Example Acceptable all the time protocol Designer { func

    createDesign(requirements: Requirements) -> Design } protocol Developer { func createApp(requirements: Requirements, design: Design) -> App } extension SkeumorphicDesigner : Designer {} extension FlatDesigner : Designer {} extension ObjectiveCDeveloper : Developer {} extension SwiftDeveloper : Developer {}
  8. Coding Example Acceptable all the time class AppFoundry { private

    let developer:Developer private let designer:Designer init(developer: Developer, designer: Designer) { self.developer = developer self.designer = designer } func createApp(requirements:Requirements) -> App { let design = designer.createDesign(requirements) return developer.createApp(requirements, design: design) } }
  9. Coding Example Acceptable all the time let developer = ObjectiveCDeveloper()

    let designer = SkeumorphicDesigner() let oldSchoolFoundry = AppFoundry(developer: developer, designer: designer) oldSchoolFoundry.createApp(requirements)
  10. Coding Example Acceptable all the time let developer = ObjectiveCDeveloper()

    let designer = FlatDesigner() let playingItSaveFoundry = AppFoundry(developer: developer, designer: designer) playingItSaveFoundry.createApp(requirements)