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

DIKitで人間がクラス間の依存関係解決するのを終わらせる

yuuxeno
August 27, 2019

 DIKitで人間がクラス間の依存関係解決するのを終わらせる

yuuxeno

August 27, 2019
Tweet

More Decks by yuuxeno

Other Decks in Programming

Transcript

  1. "7JFX$POUSPMMFS "7JFX.PEFM ".PEFM "7JFX$POUSPMMFS WJFX.PEFM"7JFX.PEFM NPEFM".PEFM $7JFX$POUSPMMFS $7JFX.PEFM $.PEFM $7JFX$POUSPMMFS

    WJFX.PEFM$7JFX.PEFM NPEFM$.PEFM #7JFX$POUSPMMFS #7JFX.PEFM #.PEFM #7JFX$POUSPMMFS WJFX.PEFM#7JFX.PEFM NPEFM#.PEFM
  2. 3FBM8PSME 7JFX$POUSPMMFS WJFX.PEFM7JFX.PE FX$POUSPMMFS WJFX. PEFM7JFX. PEFM N PEFM. PEFM

    7JFX$POUSPMMFS B7$"7JFX$POUSPMMFS C7$#7JFX$POUSPMMFS D7$$7JF POUSPMMFS WJFX.PEFM7JFX.PEFM NPEFM.PEFM ".PEFM NPEFM#.PEFM NPEFM$.PEFM FS WJFX.PEFM7JFX.PEFM NPEFM$.PEFM 7JFX$POUSPMMFS WJFX.PEFM7JFX.PEFM NPEFM FS WJFX.PEFM7JFX.PEFM E.PEFM%.PEFM F.PEFM&.PEFM D.PEFM$.PE X$POUSPMMFS WJFX.PEFM7JFX.PEFM NPEFM.PEFM
  3. ݟ௨͕͠ѱ͍ class ViewController: UIViewController { let viewModel = ViewModel(model: Model())

    func showMessage() { ͨͩͷੜ੒ॲཧ ͜ͷΫϥεຊདྷͷػೳ
  4. ਓ͕ؒ؅ཧ͢Δඞཁ class AppResolverImpl { func resolveViewController() -> ViewController { return

    ViewController(viewModel: ViewModel(model: Model())) } func resolveAViewController() -> AViewController func resolveBViewController() -> BViewController func resolveCViewController() -> CViewController ɾ ɾ ɾ ίʔυϨϏϡʔͳͲ͕ඞཁ
  5. ཉ͍͠΋ͷΛએݴ͢Δ͚ͩ class ViewController: UIViewController, Injectable { struct Dependency { let

    aViewController: AViewController let bViewController: BViewController let cViewController: CViewController } class AViewController: UIViewController, Injectable { struct Dependency { let viewModel: AViewModel } class AViewModel: Injectable { struct Dependency { let model: AModel } ɾ ɾ ɾ
  6. 9DPEFΛ࣮ߦ // // Resolver.swift // Generated by dikitgen. // import

    DIKit import UIKit extension AppResolver { func resolveAModel() -> AModel { return provideAModel() } func resolveAViewController() -> AViewController { let aViewModel = resolveAViewModel() return AViewController(dependency: .init(viewModel: aViewModel)) } func resolveAViewModel() -> AViewModel { let aModel = resolveAModel() return AViewModel(dependency: .init(model: aModel)) } func resolveBModel() -> BModel { return provideBModel() } func resolveBViewController() -> BViewController { let bViewModel = resolveBViewModel() return BViewController(dependency: .init(viewModel: bViewModel)) } func resolveBViewModel() -> BViewModel { let bModel = resolveBModel() return BViewModel(dependency: .init(model: bModel)) } func resolveCModel() -> CModel { return provideCModel() } func resolveCViewController() -> CViewController { let cViewModel = resolveCViewModel() return CViewController(dependency: .init(viewModel: cViewModel)) } func resolveCViewModel() -> CViewModel { let cModel = resolveCModel() return CViewModel(dependency: .init(model: cModel)) } func resolveViewController() -> ViewController { let aViewController = resolveAViewController() let bViewController = resolveBViewController() let cViewController = resolveCViewController() return ViewController(dependency: .init(aViewController: aViewController, bViewController: bViewController, cViewController: cViewController)) } } func resolveCViewController() -> CViewController { let cViewModel = resolveCViewModel() return CViewController(dependency: .init(viewMode cViewModel)) } func resolveCViewModel() -> CViewModel { let cModel = resolveCModel() return CViewModel(dependency: .init(model: cModel } func resolveViewController() -> ViewController { let aViewController = resolveAViewController() let bViewController = resolveBViewController() let cViewController = resolveCViewController() return ViewController(dependency: .init(aViewCont aViewController, bViewController: bViewController, cViewC cViewController)) } }
  7. ࢀߟ͓͢͢Ίهࣄ w J04%$Ͱʮίʔυੜ੒ʹΑΔ੩తͳ%FQFOEFODZ*OKFDUJPOʯʹ͍ͭͯ࿩͠ ͨޱ಄ݪߘΛެ։ IUUQTCMPHJTILBXBPSH   w ʮͳͥ%* ґଘੑ஫ೖ

    ͕ඞཁͳͷ͔ʁʯʹ͍ͭͯ(PPHMF͕ղઆ͍ͯ͠Δϖʔ δΛ຋༁ͨ͠ IUUQTRJJUBDPNNJ[VOPXBOLPJUFNT FFEGDDBBED  w ΍͸Γ͋ͳͨํͷ%FQFOEFODZ*OKFDUJPO͸·͕͍ͪͬͯΔɻ IUUQ CMPHBXBZPVUOFUCMPHZPVSEFQFOEFODZJOKFDUJPOJT XSPOHBT*FYQFDUFE