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

VIPER Architecture から学ぶ Dependency Injection

VIPER Architecture から学ぶ Dependency Injection

iOS Test Night #5 - connpass https://testnight.connpass.com/event/59283/

star__hoshi

July 26, 2017
Tweet

More Decks by star__hoshi

Other Decks in Technology

Transcript

  1. ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business

    Logic) • Presenter - View ͱ Interactor Λ஥հ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection
  2. ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business

    Logic) • Presenter - View ͱ Interactor Λ஥հ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection
  3. View protocol UserView: class { var presenter: UserPresentation { get

    } init(presenter: UserPresentation) } final class UserViewController: UIViewController, UserView { let presenter: UserPresentation init(presenter: UserPresentation) { self.presenter = presenter } }
  4. Presenter protocol UserPresentation: class { var router: UserWireframe { get

    } init(router: UserWireframe) } final class UserPresenter: UserPresentation { let router: UserWireframe init(router: UserWireframe) { self.router = router } }
  5. Router protocol UserWireframe: class { static func assembleModule() -> UIViewController

    } final class UserRouter: UserWireframe { static func assembleModule() -> UIViewController { let router = UserRouter() let presenter = UserPresenter(router: router) let view = UserViewController(presenter: presenter) return view } }
  6. ؔ܎ੑ • ந৅ʹґଘ͍ͯ͠Δ • ͦΕͧΕ͕ Protocol Λ࣮૷͠ɺ Protocol ʹґଘ͍ͯ͠Δ •

    Router ͚͕ͩ۩৅ΫϥεΛ Initialize ͍ͯ͠Δ • Router Ͱ DI ͍ͯ͠Δʂ
  7. DI ͷୈҰา final class UserPresenter: UserPresentation { let router: UserWireframe

    init(router: UserWireframe) { self.router = router } } final class UserPresenter: UserPresentation { let router: UserWireframe init() { self.router = UserRouter() } } ❌ ⭕
  8. ςετίʔυ class UserPresenterSpec: QuickSpec { override func spec() { let

    router = MockUserRouter() let presenter = UserPresenter(router: router) describe("viewDidLoad") { beforeEach { presenter.viewDidLoad() } it("…") { … } } } }