モバイルアプリ開発に使える設計の話

0886c70b5ecf3b0b0ee6500c5e47884d?s=47 M.Inomata
November 16, 2018

 モバイルアプリ開発に使える設計の話

iOS/Android開発をクリーンアーキテクチャで設計、開発する話です。

0886c70b5ecf3b0b0ee6500c5e47884d?s=128

M.Inomata

November 16, 2018
Tweet

Transcript

  1. ϞόΠϧΞϓϦ։ൃʹ ࢖͑Δઃܭͷ࿩ (iOS/Android)

  2. ࣗݾ঺հ גࣜձࣾ tech vein ୅ද ழມ ॆԝ (͍ͷ·ͨ ΈͭͻΖ) ձࣾHP:

    https://www.tech-vein.com/ private twitter: @ino2222
  3. ձࣾ(tech vein)ͷ঺հ 2013೥͔Β͋ΔେࡕຊொͷडୗγεςϜ։ൃձࣾͰ͢ɻ Android / iOS εϚʔτϑΥϯΞϓϦ։ൃ΍ɺ WebγεςϜ։ൃ(PHPɾJS)͕ಘҙͰ͢ɻ গਓ਺ͷٕज़తͳ͜ͱɾ໘ന͍͜ͱ͕޷͖ͳϝϯόʔ͕ू·ͬ ͯͰ͖ͨɺখ͞ͳձࣾͰ͢ɻ

    ձ໊ࣾ͸ςοΫϕΠϯͱಡΈ·͢ɻ
  4. ࣗࣾެ։தͷAndroid/iOSΞϓϦ ι΢ϧΞϯϦʔγϡ ࣗ෼ͷΦϦΩϟϥΛ࡞ΔεϚϗ31( IUUQTPVOUFDIWFJODPN IUUQTCJUMZ);BV3 $IJJ2 ஍ҬͰॿ͚߹͑Δಗ໊૬ஊΞϓϦ IUUQTBQQMFDP,[IYD ϙέοτΞϒετϥΫτ ҩྍैࣄऀ޲͚ͷ࠷৽δϟʔφϧߪಡΞϓϦ

  5. ࠓ೔ͷςʔϚ ϞόΠϧΞϓϦ։ൃʹAndroid/iOSωΠςΟϒ։ൃʹ͓͚Δݸਓ తϕλʔͳઃܭʹ͍ͭͯɻ iOSத৺ɻAndroid։ൃʹ͍ͭͯ͸ҎԼͷΑ͏ʹಡΈସ͑ͯͩ͘ ͍͞ɻ ViewController(ུশVC) → Activity + Fragment

    UIKitϑϨʔϜϫʔΫ → Android Framework ※Flutter, React Native, Xamarin ͸৮Ε·ͤΜɻ༻ޠΛஔ͖׵͑ͨΒԠ༻Ͱ͖Δ͸ͣɻ
  6. ઃܭɾ࣮૷ͰΑ͋͘Δ೰Έ Fat ViewController (Fat Activity)ΛͳΜͱ͔ͨ͠ ͍ɻ MVC/MVVM/MVPΛ࠾༻͕ͨ͠ɺ࣮૷ऀʹΑͬͯ Ϟσϧͷ࣮૷ϧʔϧ͕ҧ͏ɻಛఆͷϞσϧ͕ංେԽ ͢ΔɻFatViewController vs

    FatModel
  7. ϞόΠϧΞϓϦ͸Ͳͷઃܭ͕ ͍͍ͷ͔໰୊ ཚཱ͢ΔMVͳΜͱ͔ɻ MVC? MVP? MVVM? OSఏڙͷඪ४ϑϨʔϜϫʔΫ(UIKit)͕͋Δͷ ʹMVͳΜͱ͔ͳΜͯෆཁͳͷͰ͸ɻ

  8. ೰ΈͷղܾͷͨΊɺ
 ࠓճ঺հ͢Δઃܭ(ΞʔΩςΫνϟ) • MVVM + ΫϦʔϯΞʔΩςΫνϟ • ิॿϥΠϒϥϦ: Rx, DI

  9. Clean Architecture?

  10. MVVM+Clean Architecture <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU

    seCase FetchTimelineU seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ϓϨθϯ ςʔγϣϯ૚ υϝΠϯ૚ Πϯϑϥ૚
  11. Clean Architectureͷجຊݪଇ • ΫϦʔϯͳઃܭʹ͢ΔͨΊͷϧʔϧɻ • ϏδωεϧʔϧɾσʔλΛத৺ͱͯ͠ɺUIɾAPIͳͲͷ ֎෦ΠϯλʔϑΣΠεΛϓϥάΠϯԽ͢Δɻ • ґଘؔ܎Λ̍ํ޲ʹ͢Δɻ •

    ͨͩ͠ৗʹ಺ଆ͸֎ଆΛ஌Βͳ͍Α͏ʹඞཁʹԠͯ͡ґ ଘؔ܎Λٯసͤ͞Δɻ • ૚Λ·͙ͨࢀর͸ΠϯλʔϑΣΠεΛܦ༝͢Δɻ
  12. Clean Architectureͷݪଇʁ • ݪଇ͸γϯϓϧͳϧʔϧͰɺMVʙͷΑ͏ͳɺಛఆͷΫϥεߏ੒ʹറΔ ΋ͷͰ͸ͳ͍ɻ
 ———- • ݪଇΛकΕ͹MVC, MVP, MVVM

    ͳͲ೚ҙͷΞʔΩςΫνϟͱ૊Έ߹Θ ͤͯΑ͍ɻ • Clean Architectureࣗମ͸ϋʔυ΢ΣΞ։ൃͳͲ͍͔ͳΔ։ൃͰ΋ద༻ Ͱ͖Δߟ͑ํͱͯ͠ఏএ͞Ε͍ͯΔɻ
 
 
 ˠ.77.ϕʔεͷ$MFBO"SDIJUFDUVSFΛ࠾༻
  13. Clean Architecture ͷجຊ4૚ • ֎෦ΠϯλʔϑΣΠε
 (UIͱ͔DB, APIͱ͔) • ΠϯλʔϑΣΠεΞμϓλ •

    Ϣʔεέʔε • ΤϯςΟςΟ(σʔλ)
 ͷ̐૚ɻ૚͸૿͑ͯ΋ݮͬͯ΋OK͕ͩɺ
 ґଘؔ܎͸ඞͣकΔɻ
  14. ֎෦ΠϯλʔϑΣΠε(੨) • (OSϑϨʔϜϫʔΫؚΉ)ΞϓϦͷ֎ͷੈքͱͷ઀߹෦෼ɻ • ϢʔβʹݟͤΔUI෦෼ɻը໘ɾϏϡʔͷݟͨ໨΍ɺλοϓ ૢ࡞ͳͲͷΠϯλϥΫγϣϯ΍ɺ • ϋʔυ΢ΣΞɺWebAPIɺσʔλϕʔεͳͲɺΞϓϦ֎Ͱ ఆٛ͞ΕΔ֤छΠϯλʔϑΣΠε͕֘౰ɻ •

    (ಉ͡૚͕ͩɺUIͱWebAPIɺWebAPIͱσʔλϕʔεͳͲ ผͷ֎෦ΠϯλʔϑΣΠεಉ࢜͸͓ޓ͍Λ஌Βͳ͍)
  15. ΠϯλʔϑΣΠεΞμϓλ(྘) • ֎෦ΠϯλʔϑΣΠεͱUseCaseͷؒͷ૬ޓ ม׵Λߦ͏૚ɻ • ΠϯλʔϑΣΠεΞμϓλ͸੨(֎෦Πϯλʔ ϑΣΠε)Λ஌Βͳ͍ɻ

  16. Ϣʔεέʔε(੺) • ϏδωεϩδοΫΛهड़͢Δ૚ɻ • ̍ػೳ(ʹϢʔεέʔε)̍UseCaseΫϥεͱ͠ ࣮ͯݱ͢Δɻ • Ϣʔεέʔε͸྘(ΠϯλʔϑΣΠεΞμϓ λ)ɾ੨(֎෦ΠϯλʔϑΣΠε)Λ஌Βͳ͍ɻ

  17. ΤϯςΟςΟɾσʔλ(ԫ) • ΞϓϦ಺Ͱڞ௨ʹ࢖͏σʔλΛఆٛ͢Δ૚ɻ • ΤϯςΟςΟ͸ଞͷ૚ΛҰ੾஌Βͳ͍ɻ ˞%#ϨίʔυͷΤϯςΟςΟɺ"1*ϦΫΤετɾϨεϙϯεͳͲ ֎෦ΠϯλʔϑΣΠεґଘͷσʔλ͸͜͜ʹؚ·ͳ͍ɻ ֎෦ΠϯλʔϑΣΠε૚ʹҐஔ͢Δ

  18. ࣗ෼ΑΓ֎૚Λ஌Βͳ͍ ˒໼ҹͷ޲͖ ґଘͷํ޲ ʹ஫໨ <Interface> TimelineReposit ory <Data> Message MessageView

    <UseCase> FetchTimelineU seCase FetchTimelineU seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ࠨ͸ӈʹґଘ ࢀর ͍ͯ͠Δ ࠨ͸ӈΛܧঝ ࣮૷ ͍ͯ͠Δ
  19. <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU

    seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ࣗ෼ΑΓ֎૚Λ஌Βͳ͍ 6*͕஌Δੈք <Data> Message MessageView TimelineView Controller <Interface> TimelineViewM odel <Data> User UI (ExternalInterface) Entity
  20. <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU

    seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ࣗ෼ΑΓ֎૚Λ஌Βͳ͍ 7JFX.PEFM͕஌Δੈք <Data> Message <UseCase> FetchTimelineU seCase TimelineViewM odelImpl <Interface> TimelineViewM odel <Data> User ViewModel (InterfaceAdapter) Entity
  21. ࣗ෼ΑΓ֎૚Λ஌Βͳ͍ 6TF$BTF͕஌Δੈք <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU

    seCase FetchTimelineU seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource <Interface> TimelineReposit ory <Data> Message <UseCase> FetchTimelineU seCase FetchTimelineU seCaseImpl <Data> User UseCase Entity
  22. <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU

    seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ࣗ෼ΑΓ֎૚Λ஌Βͳ͍ &OUJUZ͕஌Δੈք <Data> Message <Data> User Entity
  23. <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU

    seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ಉ͡֎෦ΠϯλʔϑΣΠε૚(੨)Ͱ΋ɺ ผͷ֎෦ΠϯλʔϑΣΠεಉ࢜͸ؔ஌͠ͳ͍ 5XJUUFS"1*ΫϥΠΞϯτɾ4%,͕஌Δੈք ☓ TwitterAPICli ent / SDK <Data> TwitterMessage <Data> TwitterUser TwitterAPI&SDK (ExternalInterface)
  24. <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU

    seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ಉ͡Ξμϓλ૚(྘)Ͱ΋ɺ ผͷ֎෦ΠϯλʔϑΣΠεಉ࢜͸ؔ஌͠ͳ͍ɻ %BUB4PVSDF͕஌Δੈք ☓ <Interface> TimelineReposit ory <Data> Message TwitterAPICli ent / SDK <Data> TwitterMessage <Data> User <Data> TwitterUser Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ΠϯλʔϑΣΠεΞμϓλͷଘࡏҙٛ͸ɺ ͋͘·Ͱಛఆͷ֎෦ΠϯλʔϑΣΠεΛ6TF$BTFͰ ѻ͑ΔΠϯλʔϑΣΠε 3FQPTJUPSZ࣮૷ ʹม׵͢Δ͜ͱʹ͋Δɻ
  25. ৑௕͚ͩͲԿ͕خ͍͠ͷ͔ • ֎෦ΠϯλʔϑΣΠεͷࣄ৘ΛϢʔεέʔεʢϏδωεϩδο Ϋʣ͔Β੾Γ཭͢ࣄ͕Ͱ͖Δɻ • ֎෦ΠϯλʔϑΣΠεͱϏδωεϩδοΫʢϢʔεʣέʔε ͸͓ޓ͍ʹਂ͘஌Βͳ͍··࣮૷Ͱ͖Δɻ • มߋͷӨڹ͕ہॴԽͰ͖ΔͷͰɺػೳ௥Ճ΍ࠩ͠ସ͕͑؆ ୯ɺ҆શʹͳΔɻ֎෦ΠϯλʔϑΣΠεΛ෦඼Խ(ϓϥάΠ

    ϯԽ)Ͱ͖Δɻ • ෳ਺ਓͰ࡞ۀ͠΍͍͢ɻιʔείʔυ͕ԚΕʹ͍͘ʂ
  26. ֎૚ʹґଘ͠ͳ͍ ֎૚ʹରͯ͠ґଘ͕ͳ͍ ʹ֎૚ͷมߋʹ͍ͭͯɺ಺૚͸҆શ <Interface> TimelineReposit ory <Data> Message MessageView <UseCase>

    FetchTimelineU seCase FetchTimelineU seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource <Interface> TimelineReposit ory <Data> Message <UseCase> FetchTimelineU seCase FetchTimelineU seCaseImpl <Data> User UseCase Entity <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource <Data> Message <UseCase> FetchTimelineU seCase TimelineViewM odelImpl <Interface> TimelineViewM odel <Data> User ViewModel (InterfaceAdapter) Entity
  27. ಺૚ʹ΋࠷௿ݶ͔͠ґଘ͠ͳ͍ <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase

    FetchTimelineU seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource <Interface> TimelineReposit ory <Data> Message <UseCase> FetchTimelineU seCase <Interface> TimelineViewM odel <Data> User Entity ಺૚ʹରͯ͠ΠϯλʔϑΣΠεɾσʔλʹ͔͠ґଘ͠ͳ͍ ʹ಺૚ͷ಺෦มߋʹ͍ͭͯɺ֎૚΋҆શ
  28. ֎෦ΠϯλʔϑΣΠεͷมߋɾࠩ͠ସ͑ͷӨڹ ͕খ͍͞ <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU

    seCase FetchTimelineU seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource FacebookAPI Client / SDK <Data> FacebookMessa ge <Data> FacebookUser DataSource (InterfaceAdapter) FacebookAPI&SDK (ExternalInterface) FacebookAPI DataSource 5XJUUFSґଘΫϥε͕%BUB4PVSDF"1*ΫϥΠΞϯτ࣮૷಺ʹӅṭ͞Ε͍ͯΔͷͰɺ 5XJUUFSˠ'BDFCPPLʹมΘͬͯ΋ɺଞͷ૚ͷΫϥεΛҰ੾ม͑ͳͯ͘Α͍ɻ Өڹൣғ͸͚ͩ͜͜ʂˠ
  29. <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU

    seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource ϏδωεϩδοΫͷมߋ͕ ֎෦ΠϯλʔϑΣΠεɾUIʹӨڹ͠ͳ͍ ͨͱ͑͹ɺλΠϜϥΠϯͷϧʔϧɾ৚݅Λදࣔ͢ΔͳͲɻ ࣮૷ࡁ3FQPTJUPSZͷ૊Έ߹ΘͤͰࡁΉͳΒɺ%BUB4PVSDF"1* 4%, ҎԼ͸มߋෆཁɻ ݟͨ໨ͷมߋ͕ཁΒͳ͍ͳΒɺ7JFX.PEFM6*΋มߋෆཁɻ
  30. <Interface> TimelineReposit ory <Data> Message MessageView <UseCase> FetchTimelineU seCase FetchTimelineU

    seCaseImpl TimelineView Controller TimelineViewM odelImpl TwitterAPICli ent / SDK <Interface> TimelineViewM odel <Data> TwitterMessage <Data> User <Data> TwitterUser UI (ExternalInterface) ViewModel (InterfaceAdapter) UseCase Entity DataSource (InterfaceAdapter) TwitterAPI&SDK (ExternalInterface) TwitterAPIDat aSource TimelineDetailV iewModelImpl <Interface> TimelineDetailV iewModel TimelineDetail ViewController UIͷมߋ͕ ϏδωεϩδοΫɾσʔλ΍֎෦ΠϯλʔϑΣΠε ʹґଘ͠ͳ͍ ͨͱ͑͹ɺλΠϜϥΠϯͷݟͨ໨ͷมߋ΍ɺৄࡉը໘௥ՃͳͲɻ طଘ6TF$BTF͚ͩͰ࣮ݱͰ͖ΔͳΒɺϓϨθϯ૚ͷมߋ͚ͩͰࡁΉɻ
  31. ΫϦʔϯΞʔΩςΫνϟͷΩϞ ੍ޚͷ൓స(Inversion of Control) • ͜ΕͩͱɺϏδωεϩδοΫ͕֎෦ΠϯλʔϑΣΠε΍UIʹґଘͯ͠͠·͍ɺΫϦʔϯΞʔΩς ΫνϟͷઃܭϧʔϧΛकΕͳ͍ͷͰ͜͏͍ͨ͠ɻ TimelineViewM odel TimelineView

    Controller FetchTimelineU seCase TwitterAPIDat aSource TwitterAPICli ent / SDK ґଘͷ޲͖Λ൓స͍ͨ͠ ⇛ͦ͜Ͱ੍ޚͷ൓స *P$ Λ׆༻͢Δʂ TimelineViewM odel TimelineView Controller FetchTimelineU seCase TwitterAPIDat aSource TwitterAPICli ent / SDK ͜͏ͳΔ • ૉ௚ʹ࣮૷͢ΔͱɺॲཧͷྲྀΕʹґଘؔ܎ʹͳΔɻ
  32. • ྫɿTimelineUseCaseImpl ͔Β TimelineDataSource Λ࢖͏ɻ ࣮૷ྫ(੍ޚͷ൓సͳ͠) %BUB4PVSDFΫϥε 6TF$BTF*NQMΫϥεͰ%BUB4PVSDFར༻ ˢ%BUB4PVSDFʹ ɹɹґଘ͢ΔͷΛ΍Ί͍ͨɻ

  33. ੍ޚͷ൓స͋Γ 6TF$BTF*NQMΫϥεͷ֎͔Β%BUB4PVSDFΠϯελϯεΛ༩͑Δɻ ˢ֎෦͔ΒSFQPTJUPSZΠϯελϯε Λड͚औΔΑ͏ʹมߋɻ 6TF$BTF*NQM͸3FQPTJUPSZΠϯλʔ ϑΣΠε͔͠஌Βͳ͍Α͏ʹͳͬͨɻ ˢ6TF$BTF*NQMॳظԽ࣌ʹ %BUB4PVSDFΠϯελϯεΛࠩ͠ࠐΉɻ 6TF$BTF*NQMΫϥεͰ͸3FQPTJUPSZࢀর͢ΔΑ͏ʹͯ͠ɺ
 %BUB4PVSDFΠϯελϯεԽΛ͠ͳ͍ɻ

    %BUB4UPSF͕3FQPTJUPSZΛܧঝ
  34. ੍ޚͷ൓స FetchTimelineU seCaseImpl TwitterAPIDat aSource FetchTimelineU seCaseImpl FetchTimelineR epository TwitterAPIDat

    aSource ͜Ε͕ɺ ͜͏ͳͬͨʂ %BUB4PVSDFΛ஌Βͳ͍ ˠ5XJUUFS"1*%BUB4PVSDF͕ ೖΕସΘͬͯ΋ؾ͔ͮͳ͍ʂ
  35. ˢ͜ͷΑ͏ʹ಺෦Ͱ͸ΠϯλʔϑΣΠε͔͠஌Βͣɺ֎෦͔Β࣮ମΠϯελϯεΛ஫ೖ͢ Δ࢓૊Έͷ͜ͱΛ%* %FQFOEFODZ*OKFDUJPOґଘؔ܎ͷ஫ೖ ͱݺͼ·͢ɻ %*͸ศརͳ൓໘ɺ࿈࠯͢Δͱੜ੒ॲཧʢʹղܾʣ͕େมʹͳΓ͕ͪͰ͢ɻ ྫɿ"Λ࡞Δʹ͸#͕͍Δɺ#Λ࡞Δʹ͸$ͱ%͕͍Δʜ͔͠΋"͸͋ͪͪ͜Ͱ࢖͏FUD ͦͷͨΊɺ%*Λ࿈࠯తʹ஫ೖͯ͠ΠϯελϯεΛ࡞ͬͨΓอ࣋ͨ͠Γͯ͘͠ΕΔ ศརػߏΛ࢖͏͜ͱ͕ଟ͍Ͱ͢ɻ ͦͷศརػߏͷ͜ͱΛɺ%*ίϯςφͱݺͼ·͢ɻ %*ίϯςφ͸ɺJ04ͳΒ4XJOKFDUɺ"OESPJEͳΒ%BHHFSΛ࢖͍ͬͯ·͢ɻ

    ੍ޚͷ൓సͱDIͱίϯςφ
  36. DIղܾͷΠϝʔδ 7JFX.PEFM" 6TF$BTF" 6TF$BTF# %BUB4PVSDF" %BUB4PVSDF# 7JFX$POUSPMMFS" %BUB4PVSDF$ ໼ҹશ෦ɺDIͰࠩ͠ࠐΜͰ࣮ݱ 6TF$BTF#

    %BUB4PVSDF# %BUB4PVSDF$ 6TF$BTF#͕΄͚͠Ε͹ %BUB4PVSDF# $͚ͩࠩ͠ࠐΈ
  37. RxͰඇಉظॲཧͱଟஈॲཧΛָʹ ͢Δ • Rx=Reactive Extension
 ඇಉظॲཧͱಉظॲཧΛ۠ผͤͣετϦʔϜͱͯ͠εϚʔ τʹѻ͑ΔΑ͏ʹͳΔϥΠϒϥϦ(RxSwift / RxJava)ɻ •

    ΫϦʔϯΞʔΩςΫνϟͷઃܭࢥ૝ͷϏδωεϩδοΫ ʹʮ؀ڥ΍ϥΠϒϥϦ΁ͷґଘΛͳ͘͢ʯͱ͸൓͠· ͕͢ɺ֤૚ͷग़ྗͱͯ͠RxΛ࢖͏ͱ࣮૷ָ͕ʹͳΔͨ ΊΑ͘ར༻͍ͯ͠·͢ɻ
 ʢಛʹඇಉظपΓͱ֤૚Ͱͷσʔλม׵ॲཧָ͕ʣ
  38. RxΛ࢖ͬͨྫ View͔ΒAPIऔಘͯ݁͠ՌΛදࣔ͢Δ·Ͱ TimelineViewM odel TimelineView Controller FetchTimelineU seCase TwitterAPIDat aSource

    TwitterAPICli ent / SDK ը໘ϩʔυΠϕϯτ onLoad() execute() -> Observable<[Message]> fetchTimeline() -> Observable<[Message]> request() -> TwitterResponse response から Observable<[Message]> に 変換して結果を流す ObservableΛ ͦͷ··SFUVSO UJNFMJOFTϓϩύςΟΛ ؂ࢹͯ͠6*࠶ඳը MFUUJNFMJOFT0CTFSWBCMF<.FTTBHF> ϓϩύςΟʹ݁ՌΛྲྀ͢ λΠϜϥΠϯऔಘͰ͖ͨΒ responseΛฦ͢
  39. ·ͱΊ • ࠓͲΜͳΞʔΩςΫνϟΛ࢖͍ͬͯͯ΋ɺClean Architectureͷߟ͑ํΛ஌Δ͜ͱ͸ϝϦοτʹͳΔ͸ ͣɻ • ґଘΛ୯ํ޲ʹ͢Δɺந৅Խͯ͠ૄ݁߹ʹ͢Δɺ੍ ޚΛ൓సͯ͠֎෦ཁૉΛϓϥάΠϯԽ͢ΔɺͳͲɻ • ΫϦʔϯΞʔΩςΫνϟͷ͓ڙʹDIίϯςφɺRxΛ

    ૊Έ߹ΘͤΑ͏ɻ
  40. ࢀߟαΠτɾॻ੶ IUUQTBN[OUP1XGP) $MFBO"SDIJUFDUVSFɹ ୡਓʹֶͿιϑτ΢ΣΞͷߏ଄ͱઃܭ ·ͩ.7$ .71 .77.Ͱফ໣ͯ͠ΔͷʁJ04$MFBO"SDIJUFDUVSFʹ͍ͭͯ IUUQTRJJUBDPNLPVUBMPVJUFNTBGDGBEFDED 5IF$MFBO"SDIJUFDUVSF IUUQTCMPHDMFBODPEFSDPNVODMFCPCUIFDMFBOBSDIJUFDUVSFIUNM

  41. ͍͞͝ʹ • tech vein Ͱ͸͜ΜͳΞϓϦΤϯδχΞɺ
 ϑϦʔϥϯεɾύʔτφʔ༷Λืू͍ͯ͠·͢ɻ • RxSwift, RxJava Λ࢖͍͍ͨ

    • MVVMɺ CleanArchitectureɺ DI Λ׆༻ͨ͠ઃܭʹڵຯ͕͋Δ ڵຯ͕͋Δํɺͪΐͬͱ࿩Λฉ͍ͯΈ͍ͨํ
 ͨͩઃܭͷ࿩Λ΋ͬͱฉ͖͍ͨํ΋
 ͥͻ͓੠͕͚Լ͍͞ʂ
  42. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ 5XJUUFS!JOP

  43. ิ଍:ଞͷΞʔΩςΫνϟͱClean Architecture ͷ૊Έ߹Θͤʹ͍ͭͯ • ϓϨθϯςʔγϣϯ૚͸UI+ViewModel͚ͩͰઆ໌͠·͕ͨ͠ɺΫϦʔϯ ΞʔΩςΫνϟͰ͸റΓ͕ͳ͍෦෼ͳͷͰɺγεςϜن໛΍։ൃϝϯόʔ͕ ׳Ε͍ͯΔΞʔΩςΫνϟʹΑͬͯࣗ༝ʹબ୒ͯ͠΋͍͍ͱࢥ͍·͢ɻ • ྫɿ
 େن໛…ViewModel͸σʔλ͚ͩʹͯ͠ɺPresenterΛ༻ҙ͢Δ(Viper)


    தن໛…ViewModelΛ࢖ΘͣɺPresenter͚ͩ(MVP+CleanArchitecture)
 খن໛…ViewModel΋Presenter΋࢖Θͳ͍(M+VC+CleanArchitecture) • ·ͨɺViewModel͸Interfaceͱ͠·͕ͨ͠ɺUIมߋʹӨڹΛड͚͍͍ͯͷ Ͱ͋Ε͹ɺViewModel͸ΠϯλʔϑΣΠεԽͤͣɺ࣮ମͷΈͰ΋ྑ͍ͱࢥ͍ ·͢ɻ(ϓϨθϯ૚Λ̎૚Ͱͳ̍͘૚͚ͩͱΈͳ͢)
  44. ิ଍:Ϋϥεͷ໾ׂʢϓϨθϯ૚ʣ • ViewController / Activity
 ݸ਺ɿ̍ը໘ʢ̍෦඼ʣ̍Ϋϥεɻ
 ໾ׂɿOSͷ੍໿ʹै͍ը໘දࣔ͢Δɻ • ViewModel
 ݸ਺ɿ1ը໘̍Ϋϥεɻڞ௨UI෦඼ʹͳ͍ͬͯΔ෦෼

    ͸௥ՃͰ̍෦඼(1View)1Ϋϥεɻ
 ໾ׂɿUIͷΠϕϯτೖྗΛड͚෇͚ɺUIදࣔ͢Δσʔ λɾঢ়ଶΛอ࣋ɾग़ྗ͢Δ
  45. ิ଍:Ϋϥεͷ໾ׂʢυϝΠϯ૚ʣ • UseCase
 ݸ਺ɿ̍ػೳ̍Ϋϥεɻ
 ໾ׂɿ̍ͭͷػೳΛ࣮ݱ͢Δ(ྫɿձһొ࿥͢Δɺ͓ؾʹೖΓ௥Ճ͢Δ) • Repository
 ݸ਺ɿػೳΛߏ੒͢Δཁૉ܈ΛάϧʔϓԽͱͯ͠ɺ̍άϧʔϓ̍Ϋϥεɻ
 ໾ׂɿUseCaseͷߏ੒ཁૉΛఏڙ͢Δɻ
 ྫɿձһ৘ใϦϙδτϦ…ձһ৘ใΛ࡞੒

    / ߋ৽ / ࡟আ͢Δ
 λΠϜϥΠϯϦϙδτϦ…λΠϜϥΠϯϦετऔಘɺݕࡧ৚݅ΛߜͬͯϦετऔಘɺ͓ؾʹೖΓ ϝοηʔδొ࿥/࡟আ
 ϝοηʔδ౤ߘϦϙδτϦ…ϝοηʔδૹ৴/࡟আɺDMૹ৴/࡟আ • ModelΦϒδΣΫτ(σʔλ)
 ݸ਺ɿ̍σʔλ୯Ґ̍Ϋϥε
 ໾ׂɿϝοηʔδɺϢʔβͳͲͷσʔλΛ΋ͭγϯϓϧͳΦϒδΣΫτɻσʔλՃ޻ͷͨΊͷ؆୯ͳϝ ιουΛ࣋ͭ͜ͱ΋ɻ
  46. ิ଍:Ϋϥεͷ໾ׂʢΠϯϑϥ૚ʣ • DataSource
 ݸ਺ɿ̍֎෦ΠϯλʔϑΣΠε͋ͨΓ̍Ϋϥεɻ
 ໾ׂɿಛఆͷWebAPIɺOSػೳɺDBͳͲΛૢ࡞͢ΔͨΊͷػೳΛ Repositoryཁ݅ʹ߹Θͤͯఏڙ͢ΔΫϥεɻ • Entity (֎෦ΠϯλʔϑΣΠεґଘ)
 ໾ׂɿAPIϦΫΤετɺϨεϙϯεɺDBϨίʔυͳͲ֎෦ΠϯλʔϑΣΠ

    ε͕ཁٻ͢Δσʔλܕ࣮૷ɻ͜ͷܕͷ··Repositoryʹ౉ͯ͠͸͍͚ͳ ͍ɻ • ͦͷଞ(DataStore͔ΒͷΈ࢖͏)
 APIΫϥΠΞϯτϥΠϒϥϦɺDB࣮૷ΫϥεͳͲɻ
  47. ิ଍ɿਤͰDataSource͕̎৭ʹ ͳ͍ͬͯͨͷ͕ؾʹͳΔ • ͜ͷDataSource͸֎෦ΠϯλʔϑΣΠε(੨)Λ஌ͬͯ͠·͍ͬͯΔՄೳੑ͕͋ΔͨΊɺ InterfaceAdapterͳ͠ͷ֎෦ΠϯλʔϑΣΠεͷΑ͏ͳҐஔ͚ͮʹͳΔͱߟ͑ศ্ٓ̎৭Ͱද͍ͯ͠· ͢ɻ • ࣮ࡍʹ͸TwitterAPIClientͳͲ͕ϥΠϒϥϦʹΑͬͯந৅Խ͞Ε͍ͯΔ৔߹΋͋Γɺͦ͜ʹΠϯλʔϑΣ ΠεΛ଍͢ͱ৑௕ʹͳΓ·͢͠ɺͦ͏Ͱͳ͍৔߹΋ϏδωεϩδοΫͱ͸RepositoryΠϯλʔϑΣΠε Ͱ҆શʹ੾Γ཭͞Ε͍ͯΔͨΊɺ͜͜Ͱ͸ඞͣ͠΋ΠϯλʔϑΣΠεΛ৽ͨʹ༻ҙ͢Δඞཁ͸ͳ͍ͱߟ

    ͍͑ͯ·͢ɻ • ̐૚Ͱ࣮૷͢ΔͳΒDataSource͸ΠϯλʔϑΣΠεΞμϓλ(྘)Ͱ͢ͷͰɺTwitterAPIClientͷinterface Λ༻ҙ͢Ε͹֎෦ΠϯλʔϑΣΠε(੨)Λ஌Βͳͯ͘΋Α͘ͳΓ·͢ɻ • ৗʹ෼཭͢Δͱ֎෦ΠϯλʔϑΣΠε༻ͷσʔλܕͷӅṭ΋ඞཁͳͷͰେมͰ͕͢ɺDataSource͕ෳ ࡶʹͳ͖ͬͯͯɺ֎෦ΠϯλʔϑΣΠεͱͷґଘΛബͨ͘͘͠ͳͬͨΒ෼཭͢Δ΄͏͕͍͍Ͱ͠ΐ͏ɻ DataSource (InterfaceAdapter) TwitterAPIDat aSource