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

iOS Clean Architecture のすすめ

koutalou
November 17, 2016

iOS Clean Architecture のすすめ

iOS Clean Architecture の説明と、実際にMoneyForwardでiOS Clean Architectureを導入してみた話をします。

Sample code: https://github.com/koutalou/ios-cleanarchitecture

koutalou

November 17, 2016
Tweet

More Decks by koutalou

Other Decks in Technology

Transcript

  1. $MFBO"SDIJUFDUVSF 7JFX 1SFTFOUFS 6TF$BTF 5SBOTMBUPS .PEFM %BUB4UPSF &OUJUZ 3FQPTJUPSZ 1SFTFOUBUJPO-BZFS

    %PNBJO-BZFS %BUB-BZFS w ੹຿Λࡉ෼Խ͢Δ͜ͱͰɺ֤ϨΠϠ͕ԿΛ୲౰͢Δ͔໌֬ʹͳΔ w 6*ͱϏδωεϩδοΫΛ෼཭Ͱ͖ɺϨΠϠؒͷґଘΛ࠷খݶʹͰ͖Δ w ϨΠϠؒ͸ૄ݁߹ͳͷͰϞδϡʔϧͷஔ͖׵͑ɺςετ͕༰қ
  2. 1SFTFOUBUJPO-BZFS 6TF$BTF 5SBOTMBUPS .PEFM %BUB4UPSF &OUJUZ 3FQPTJUPSZ 1SFTFOUBUJPO-BZFS %PNBJO-BZFS %BUB-BZFS

    w 6*ͷදࣔ΍ΠϕϯτͷϋϯυϦϯάΛߦ͏ w ϏδωεϩδοΫ͸ؔ༩͠ͳ͍ 7JFX 1SFTFOUFS
  3. %PNBJO-BZFS 6TF$BTF 5SBOTMBUPS .PEFM %BUB4UPSF &OUJUZ 1SFTFOUBUJPO-BZFS %PNBJO-BZFS %BUB-BZFS w

    ϏδωεϩδοΫॲཧΛߦ͏ w ϏδωεϩδοΫ
 ɹ3FQPTJUPSZ QBUUFSOΛҙࣝͯ͠ɺऔಘͨ͠σʔλΛ1SFTFOUBUJPO -BZFSʹඞཁͳσʔλʹ੔ܗͯ͠ฦ͢ɺ·ͨ͸ॲཧΛ͢Δ 3FQPTJUPSZ 7JFX 1SFTFOUFS
  4. %BUB-BZFS 6TF$BTF 5SBOTMBUPS .PEFM %BUB4UPSF &OUJUZ 1SFTFOUBUJPO-BZFS %PNBJO-BZFS %BUB-BZFS w

    ௨৴΍σʔλ؅ཧΛߦ͏ w %#΍αʔόͰ؅ཧ͞ΕΔ%BUB4PVSDFΛѻ͏ w 3FQPTJUPSZ͸%PNBJO-BZFS΁ͷ*'Ͱ&OUJUZͷ$36%Λఏڙ͢Δ 3FQPTJUPSZ 7JFX 1SFTFOUFS
  5. 1SFTFOUBUJPO-BZFS 7JFX 1SFTFOUFS 6TF$BTF 1SFTFOUFS w 7JFXͱ6TF$BTFͷΠϕϯτͷڮ౉͠Λߦ͏ w ඞཁʹԠͯ͡7JFXʹ.PEFMΛ౉ͨ͠Γɺ6TF$BTFʹॲཧͤ͞Δ
 7JFX

    7JFX$POUSPMMFS  w 7JFXͷΠϕϯτΛ1SFTFOUFSʹ௨஌͢Δ w ड͚औͬͨ.PEFM΍εςʔλεʹΑΓදࣔΛ੾Γସ͑Δ .PEFM΍4UBUVT৘ใ 7JFXͷ&WFOU .PEFM΍ॲཧ݁Ռ ॲཧͷཁٻ
  6. %PNBJO-BZFS 5SBOTMBUPS 1SFTFOUFS 6TF$BTF 6TF$BTF w ϢʔεέʔεʹඞཁͳϩδοΫॲཧΛهड़͢Δ 5SBOTMBUPS w 6TF$BTF͕औಘͨ͠&OUJUZΛ7JFXʹඞཁͳ.PEFMʹม׵͢Δ

    .PEFM w 7JFXͷදࣔʹඞཁͳ7BMVF0CKFDU &OUJUZ .PEFM΍ॲཧ݁Ռ ॲཧͷཁٻ &OUJUZ΍݁Ռ σʔλͷཁٻ 3FQPTJUPSZ .PEFM
  7. %BUB-BZFS 6TF$BTF 3FQPTJUPSZ w %BUB4PVSDFͷ$36%૬౰ͷ*' %BUB4UPSF w ࣮ࡍʹ௨৴΍σʔλ؅ཧΛߦ͏ &OUJUZ w

    %#΍αʔόͰ؅ཧ͞ΕΔ7BMVF0CKFDU &OUJUZ΍݁Ռ σʔλͷཁٻ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