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

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

M.Inomata
November 16, 2018

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

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

M.Inomata

November 16, 2018
Tweet

More Decks by M.Inomata

Other Decks in Technology

Transcript

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

    View full-size slide

  2. ࣗݾ঺հ
    גࣜձࣾ tech vein ୅ද
    ழມ ॆԝ (͍ͷ·ͨ ΈͭͻΖ)
    ձࣾHP: https://www.tech-vein.com/
    private twitter: @ino2222

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  5. ࠓ೔ͷςʔϚ
    ϞόΠϧΞϓϦ։ൃʹAndroid/iOSωΠςΟϒ։ൃʹ͓͚Δݸਓ
    తϕλʔͳઃܭʹ͍ͭͯɻ
    iOSத৺ɻAndroid։ൃʹ͍ͭͯ͸ҎԼͷΑ͏ʹಡΈସ͑ͯͩ͘
    ͍͞ɻ
    ViewController(ུশVC) → Activity + Fragment
    UIKitϑϨʔϜϫʔΫ → Android Framework
    ※Flutter, React Native, Xamarin ͸৮Ε·ͤΜɻ༻ޠΛஔ͖׵͑ͨΒԠ༻Ͱ͖Δ͸ͣɻ

    View full-size slide

  6. ઃܭɾ࣮૷ͰΑ͋͘Δ೰Έ
    Fat ViewController (Fat Activity)ΛͳΜͱ͔ͨ͠
    ͍ɻ
    MVC/MVVM/MVPΛ࠾༻͕ͨ͠ɺ࣮૷ऀʹΑͬͯ
    Ϟσϧͷ࣮૷ϧʔϧ͕ҧ͏ɻಛఆͷϞσϧ͕ංେԽ
    ͢ΔɻFatViewController vs FatModel

    View full-size slide

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

    View full-size slide

  8. ೰ΈͷղܾͷͨΊɺ

    ࠓճ঺հ͢Δઃܭ(ΞʔΩςΫνϟ)
    • MVVM + ΫϦʔϯΞʔΩςΫνϟ
    • ิॿϥΠϒϥϦ: Rx, DI

    View full-size slide

  9. Clean Architecture?

    View full-size slide

  10. MVVM+Clean Architecture

    TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ϓϨθϯ
    ςʔγϣϯ૚
    υϝΠϯ૚ Πϯϑϥ૚

    View full-size slide

  11. Clean Architectureͷجຊݪଇ
    • ΫϦʔϯͳઃܭʹ͢ΔͨΊͷϧʔϧɻ
    • ϏδωεϧʔϧɾσʔλΛத৺ͱͯ͠ɺUIɾAPIͳͲͷ
    ֎෦ΠϯλʔϑΣΠεΛϓϥάΠϯԽ͢Δɻ
    • ґଘؔ܎Λ̍ํ޲ʹ͢Δɻ
    • ͨͩ͠ৗʹ಺ଆ͸֎ଆΛ஌Βͳ͍Α͏ʹඞཁʹԠͯ͡ґ
    ଘؔ܎Λٯసͤ͞Δɻ
    • ૚Λ·͙ͨࢀর͸ΠϯλʔϑΣΠεΛܦ༝͢Δɻ

    View full-size slide

  12. Clean Architectureͷݪଇʁ
    • ݪଇ͸γϯϓϧͳϧʔϧͰɺMVʙͷΑ͏ͳɺಛఆͷΫϥεߏ੒ʹറΔ
    ΋ͷͰ͸ͳ͍ɻ

    ———-
    • ݪଇΛकΕ͹MVC, MVP, MVVM ͳͲ೚ҙͷΞʔΩςΫνϟͱ૊Έ߹Θ
    ͤͯΑ͍ɻ
    • Clean Architectureࣗମ͸ϋʔυ΢ΣΞ։ൃͳͲ͍͔ͳΔ։ൃͰ΋ద༻
    Ͱ͖Δߟ͑ํͱͯ͠ఏএ͞Ε͍ͯΔɻ



    ˠ.77.ϕʔεͷ$MFBO"SDIJUFDUVSFΛ࠾༻

    View full-size slide

  13. Clean Architecture ͷجຊ4૚
    • ֎෦ΠϯλʔϑΣΠε

    (UIͱ͔DB, APIͱ͔)
    • ΠϯλʔϑΣΠεΞμϓλ
    • Ϣʔεέʔε
    • ΤϯςΟςΟ(σʔλ)

    ͷ̐૚ɻ૚͸૿͑ͯ΋ݮͬͯ΋OK͕ͩɺ

    ґଘؔ܎͸ඞͣकΔɻ

    View full-size slide

  14. ֎෦ΠϯλʔϑΣΠε(੨)
    • (OSϑϨʔϜϫʔΫؚΉ)ΞϓϦͷ֎ͷੈքͱͷ઀߹෦෼ɻ
    • ϢʔβʹݟͤΔUI෦෼ɻը໘ɾϏϡʔͷݟͨ໨΍ɺλοϓ
    ૢ࡞ͳͲͷΠϯλϥΫγϣϯ΍ɺ
    • ϋʔυ΢ΣΞɺWebAPIɺσʔλϕʔεͳͲɺΞϓϦ֎Ͱ
    ఆٛ͞ΕΔ֤छΠϯλʔϑΣΠε͕֘౰ɻ
    • (ಉ͡૚͕ͩɺUIͱWebAPIɺWebAPIͱσʔλϕʔεͳͲ
    ผͷ֎෦ΠϯλʔϑΣΠεಉ࢜͸͓ޓ͍Λ஌Βͳ͍)

    View full-size slide

  15. ΠϯλʔϑΣΠεΞμϓλ(྘)
    • ֎෦ΠϯλʔϑΣΠεͱUseCaseͷؒͷ૬ޓ
    ม׵Λߦ͏૚ɻ
    • ΠϯλʔϑΣΠεΞμϓλ͸੨(֎෦Πϯλʔ
    ϑΣΠε)Λ஌Βͳ͍ɻ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  18. ࣗ෼ΑΓ֎૚Λ஌Βͳ͍
    ˒໼ҹͷ޲͖ ґଘͷํ޲
    ʹ஫໨

    TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ࠨ͸ӈʹґଘ ࢀর
    ͍ͯ͠Δ
    ࠨ͸ӈΛܧঝ ࣮૷
    ͍ͯ͠Δ

    View full-size slide


  19. TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ࣗ෼ΑΓ֎૚Λ஌Βͳ͍
    6*͕஌Δੈք

    Message
    MessageView
    TimelineView
    Controller

    TimelineViewM
    odel

    User
    UI
    (ExternalInterface)
    Entity

    View full-size slide


  20. TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ࣗ෼ΑΓ֎૚Λ஌Βͳ͍
    7JFX.PEFM͕஌Δੈք

    Message

    FetchTimelineU
    seCase
    TimelineViewM
    odelImpl

    TimelineViewM
    odel

    User
    ViewModel
    (InterfaceAdapter)
    Entity

    View full-size slide

  21. ࣗ෼ΑΓ֎૚Λ஌Βͳ͍
    6TF$BTF͕஌Δੈք

    TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource

    TimelineReposit
    ory

    Message

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl

    User
    UseCase
    Entity

    View full-size slide


  22. TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ࣗ෼ΑΓ֎૚Λ஌Βͳ͍
    &OUJUZ͕஌Δੈք

    Message

    User
    Entity

    View full-size slide


  23. TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ಉ͡֎෦ΠϯλʔϑΣΠε૚(੨)Ͱ΋ɺ
    ผͷ֎෦ΠϯλʔϑΣΠεಉ࢜͸ؔ஌͠ͳ͍
    5XJUUFS"1*ΫϥΠΞϯτɾ4%,͕஌Δੈք
    ☓ TwitterAPICli
    ent / SDK

    TwitterMessage

    TwitterUser
    TwitterAPI&SDK
    (ExternalInterface)

    View full-size slide


  24. TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ಉ͡Ξμϓλ૚(྘)Ͱ΋ɺ
    ผͷ֎෦ΠϯλʔϑΣΠεಉ࢜͸ؔ஌͠ͳ͍ɻ
    %BUB4PVSDF͕஌Δੈք

    TimelineReposit
    ory

    Message
    TwitterAPICli
    ent / SDK

    TwitterMessage

    User

    TwitterUser
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    ΠϯλʔϑΣΠεΞμϓλͷଘࡏҙٛ͸ɺ
    ͋͘·Ͱಛఆͷ֎෦ΠϯλʔϑΣΠεΛ6TF$BTFͰ
    ѻ͑ΔΠϯλʔϑΣΠε 3FQPTJUPSZ࣮૷
    ʹม׵͢Δ͜ͱʹ͋Δɻ

    View full-size slide

  25. ৑௕͚ͩͲԿ͕خ͍͠ͷ͔
    • ֎෦ΠϯλʔϑΣΠεͷࣄ৘ΛϢʔεέʔεʢϏδωεϩδο
    Ϋʣ͔Β੾Γ཭͢ࣄ͕Ͱ͖Δɻ
    • ֎෦ΠϯλʔϑΣΠεͱϏδωεϩδοΫʢϢʔεʣέʔε
    ͸͓ޓ͍ʹਂ͘஌Βͳ͍··࣮૷Ͱ͖Δɻ
    • มߋͷӨڹ͕ہॴԽͰ͖ΔͷͰɺػೳ௥Ճ΍ࠩ͠ସ͕͑؆
    ୯ɺ҆શʹͳΔɻ֎෦ΠϯλʔϑΣΠεΛ෦඼Խ(ϓϥάΠ
    ϯԽ)Ͱ͖Δɻ
    • ෳ਺ਓͰ࡞ۀ͠΍͍͢ɻιʔείʔυ͕ԚΕʹ͍͘ʂ

    View full-size slide

  26. ֎૚ʹґଘ͠ͳ͍
    ֎૚ʹରͯ͠ґଘ͕ͳ͍
    ʹ֎૚ͷมߋʹ͍ͭͯɺ಺૚͸҆શ

    TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource

    TimelineReposit
    ory

    Message

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl

    User
    UseCase
    Entity

    TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource

    Message

    FetchTimelineU
    seCase
    TimelineViewM
    odelImpl

    TimelineViewM
    odel

    User
    ViewModel
    (InterfaceAdapter)
    Entity

    View full-size slide

  27. ಺૚ʹ΋࠷௿ݶ͔͠ґଘ͠ͳ͍

    TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource

    TimelineReposit
    ory

    Message

    FetchTimelineU
    seCase

    TimelineViewM
    odel

    User
    Entity
    ಺૚ʹରͯ͠ΠϯλʔϑΣΠεɾσʔλʹ͔͠ґଘ͠ͳ͍
    ʹ಺૚ͷ಺෦มߋʹ͍ͭͯɺ֎૚΋҆શ

    View full-size slide

  28. ֎෦ΠϯλʔϑΣΠεͷมߋɾࠩ͠ସ͑ͷӨڹ
    ͕খ͍͞

    TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    FacebookAPI
    Client / SDK

    FacebookMessa
    ge

    FacebookUser
    DataSource
    (InterfaceAdapter)
    FacebookAPI&SDK
    (ExternalInterface)
    FacebookAPI
    DataSource
    5XJUUFSґଘΫϥε͕%BUB4PVSDF"1*ΫϥΠΞϯτ࣮૷಺ʹӅṭ͞Ε͍ͯΔͷͰɺ
    5XJUUFSˠ'BDFCPPLʹมΘͬͯ΋ɺଞͷ૚ͷΫϥεΛҰ੾ม͑ͳͯ͘Α͍ɻ
    Өڹൣғ͸͚ͩ͜͜ʂˠ

    View full-size slide


  29. TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

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

    View full-size slide


  30. TimelineReposit
    ory

    Message
    MessageView

    FetchTimelineU
    seCase
    FetchTimelineU
    seCaseImpl
    TimelineView
    Controller
    TimelineViewM
    odelImpl
    TwitterAPICli
    ent / SDK

    TimelineViewM
    odel

    TwitterMessage

    User

    TwitterUser
    UI
    (ExternalInterface)
    ViewModel
    (InterfaceAdapter) UseCase
    Entity
    DataSource
    (InterfaceAdapter)
    TwitterAPI&SDK
    (ExternalInterface)
    TwitterAPIDat
    aSource
    TimelineDetailV
    iewModelImpl

    TimelineDetailV
    iewModel
    TimelineDetail
    ViewController
    UIͷมߋ͕
    ϏδωεϩδοΫɾσʔλ΍֎෦ΠϯλʔϑΣΠε
    ʹґଘ͠ͳ͍
    ͨͱ͑͹ɺλΠϜϥΠϯͷݟͨ໨ͷมߋ΍ɺৄࡉը໘௥ՃͳͲɻ
    طଘ6TF$BTF͚ͩͰ࣮ݱͰ͖ΔͳΒɺϓϨθϯ૚ͷมߋ͚ͩͰࡁΉɻ

    View full-size slide

  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
    ͜͏ͳΔ
    • ૉ௚ʹ࣮૷͢ΔͱɺॲཧͷྲྀΕʹґଘؔ܎ʹͳΔɻ

    View full-size slide

  32. • ྫɿTimelineUseCaseImpl ͔Β TimelineDataSource Λ࢖͏ɻ
    ࣮૷ྫ(੍ޚͷ൓సͳ͠)
    %BUB4PVSDFΫϥε
    6TF$BTF*NQMΫϥεͰ%BUB4PVSDFར༻
    ˢ%BUB4PVSDFʹ
    ɹɹґଘ͢ΔͷΛ΍Ί͍ͨɻ

    View full-size slide

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

    %BUB4PVSDFΠϯελϯεԽΛ͠ͳ͍ɻ %BUB4UPSF͕3FQPTJUPSZΛܧঝ

    View full-size slide

  34. ੍ޚͷ൓స
    FetchTimelineU
    seCaseImpl
    TwitterAPIDat
    aSource
    FetchTimelineU
    seCaseImpl
    FetchTimelineR
    epository
    TwitterAPIDat
    aSource
    ͜Ε͕ɺ
    ͜͏ͳͬͨʂ
    %BUB4PVSDFΛ஌Βͳ͍
    ˠ5XJUUFS"1*%BUB4PVSDF͕
    ೖΕସΘͬͯ΋ؾ͔ͮͳ͍ʂ

    View full-size slide

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

    View full-size slide

  36. DIղܾͷΠϝʔδ
    7JFX.PEFM"
    6TF$BTF" 6TF$BTF#
    %BUB4PVSDF" %BUB4PVSDF#
    7JFX$POUSPMMFS"
    %BUB4PVSDF$
    ໼ҹશ෦ɺDIͰࠩ͠ࠐΜͰ࣮ݱ
    6TF$BTF#
    %BUB4PVSDF#
    %BUB4PVSDF$
    6TF$BTF#͕΄͚͠Ε͹
    %BUB4PVSDF# $͚ͩࠩ͠ࠐΈ

    View full-size slide

  37. RxͰඇಉظॲཧͱଟஈॲཧΛָʹ
    ͢Δ
    • Rx=Reactive Extension

    ඇಉظॲཧͱಉظॲཧΛ۠ผͤͣετϦʔϜͱͯ͠εϚʔ
    τʹѻ͑ΔΑ͏ʹͳΔϥΠϒϥϦ(RxSwift / RxJava)ɻ
    • ΫϦʔϯΞʔΩςΫνϟͷઃܭࢥ૝ͷϏδωεϩδοΫ
    ʹʮ؀ڥ΍ϥΠϒϥϦ΁ͷґଘΛͳ͘͢ʯͱ͸൓͠·
    ͕͢ɺ֤૚ͷग़ྗͱͯ͠RxΛ࢖͏ͱ࣮૷ָ͕ʹͳΔͨ
    ΊΑ͘ར༻͍ͯ͠·͢ɻ

    ʢಛʹඇಉظपΓͱ֤૚Ͱͷσʔλม׵ॲཧָ͕ʣ

    View full-size slide

  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Λฦ͢

    View full-size slide

  39. ·ͱΊ
    • ࠓͲΜͳΞʔΩςΫνϟΛ࢖͍ͬͯͯ΋ɺClean
    Architectureͷߟ͑ํΛ஌Δ͜ͱ͸ϝϦοτʹͳΔ͸
    ͣɻ
    • ґଘΛ୯ํ޲ʹ͢Δɺந৅Խͯ͠ૄ݁߹ʹ͢Δɺ੍
    ޚΛ൓సͯ͠֎෦ཁૉΛϓϥάΠϯԽ͢ΔɺͳͲɻ
    • ΫϦʔϯΞʔΩςΫνϟͷ͓ڙʹDIίϯςφɺRxΛ
    ૊Έ߹ΘͤΑ͏ɻ

    View full-size slide

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

    View full-size slide

  41. ͍͞͝ʹ
    • tech vein Ͱ͸͜ΜͳΞϓϦΤϯδχΞɺ

    ϑϦʔϥϯεɾύʔτφʔ༷Λืू͍ͯ͠·͢ɻ
    • RxSwift, RxJava Λ࢖͍͍ͨ
    • MVVMɺ CleanArchitectureɺ DI Λ׆༻ͨ͠ઃܭʹڵຯ͕͋Δ
    ڵຯ͕͋Δํɺͪΐͬͱ࿩Λฉ͍ͯΈ͍ͨํ

    ͨͩઃܭͷ࿩Λ΋ͬͱฉ͖͍ͨํ΋

    ͥͻ͓੠͕͚Լ͍͞ʂ

    View full-size slide

  42. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ
    5XJUUFS!JOP

    View full-size slide

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

    େن໛…ViewModel͸σʔλ͚ͩʹͯ͠ɺPresenterΛ༻ҙ͢Δ(Viper)

    தن໛…ViewModelΛ࢖ΘͣɺPresenter͚ͩ(MVP+CleanArchitecture)

    খن໛…ViewModel΋Presenter΋࢖Θͳ͍(M+VC+CleanArchitecture)
    • ·ͨɺViewModel͸Interfaceͱ͠·͕ͨ͠ɺUIมߋʹӨڹΛड͚͍͍ͯͷ
    Ͱ͋Ε͹ɺViewModel͸ΠϯλʔϑΣΠεԽͤͣɺ࣮ମͷΈͰ΋ྑ͍ͱࢥ͍
    ·͢ɻ(ϓϨθϯ૚Λ̎૚Ͱͳ̍͘૚͚ͩͱΈͳ͢)

    View full-size slide

  44. ิ଍:Ϋϥεͷ໾ׂʢϓϨθϯ૚ʣ
    • ViewController / Activity

    ݸ਺ɿ̍ը໘ʢ̍෦඼ʣ̍Ϋϥεɻ

    ໾ׂɿOSͷ੍໿ʹै͍ը໘දࣔ͢Δɻ
    • ViewModel

    ݸ਺ɿ1ը໘̍Ϋϥεɻڞ௨UI෦඼ʹͳ͍ͬͯΔ෦෼
    ͸௥ՃͰ̍෦඼(1View)1Ϋϥεɻ

    ໾ׂɿUIͷΠϕϯτೖྗΛड͚෇͚ɺUIදࣔ͢Δσʔ
    λɾঢ়ଶΛอ࣋ɾग़ྗ͢Δ

    View full-size slide

  45. ิ଍:Ϋϥεͷ໾ׂʢυϝΠϯ૚ʣ
    • UseCase

    ݸ਺ɿ̍ػೳ̍Ϋϥεɻ

    ໾ׂɿ̍ͭͷػೳΛ࣮ݱ͢Δ(ྫɿձһొ࿥͢Δɺ͓ؾʹೖΓ௥Ճ͢Δ)
    • Repository

    ݸ਺ɿػೳΛߏ੒͢Δཁૉ܈ΛάϧʔϓԽͱͯ͠ɺ̍άϧʔϓ̍Ϋϥεɻ

    ໾ׂɿUseCaseͷߏ੒ཁૉΛఏڙ͢Δɻ

    ྫɿձһ৘ใϦϙδτϦ…ձһ৘ใΛ࡞੒ / ߋ৽ / ࡟আ͢Δ

    λΠϜϥΠϯϦϙδτϦ…λΠϜϥΠϯϦετऔಘɺݕࡧ৚݅ΛߜͬͯϦετऔಘɺ͓ؾʹೖΓ
    ϝοηʔδొ࿥/࡟আ

    ϝοηʔδ౤ߘϦϙδτϦ…ϝοηʔδૹ৴/࡟আɺDMૹ৴/࡟আ
    • ModelΦϒδΣΫτ(σʔλ)

    ݸ਺ɿ̍σʔλ୯Ґ̍Ϋϥε

    ໾ׂɿϝοηʔδɺϢʔβͳͲͷσʔλΛ΋ͭγϯϓϧͳΦϒδΣΫτɻσʔλՃ޻ͷͨΊͷ؆୯ͳϝ
    ιουΛ࣋ͭ͜ͱ΋ɻ

    View full-size slide

  46. ิ଍:Ϋϥεͷ໾ׂʢΠϯϑϥ૚ʣ
    • DataSource

    ݸ਺ɿ̍֎෦ΠϯλʔϑΣΠε͋ͨΓ̍Ϋϥεɻ

    ໾ׂɿಛఆͷWebAPIɺOSػೳɺDBͳͲΛૢ࡞͢ΔͨΊͷػೳΛ
    Repositoryཁ݅ʹ߹Θͤͯఏڙ͢ΔΫϥεɻ
    • Entity (֎෦ΠϯλʔϑΣΠεґଘ)

    ໾ׂɿAPIϦΫΤετɺϨεϙϯεɺDBϨίʔυͳͲ֎෦ΠϯλʔϑΣΠ
    ε͕ཁٻ͢Δσʔλܕ࣮૷ɻ͜ͷܕͷ··Repositoryʹ౉ͯ͠͸͍͚ͳ
    ͍ɻ
    • ͦͷଞ(DataStore͔ΒͷΈ࢖͏)

    APIΫϥΠΞϯτϥΠϒϥϦɺDB࣮૷ΫϥεͳͲɻ

    View full-size slide

  47. ิ଍ɿਤͰDataSource͕̎৭ʹ
    ͳ͍ͬͯͨͷ͕ؾʹͳΔ
    • ͜ͷDataSource͸֎෦ΠϯλʔϑΣΠε(੨)Λ஌ͬͯ͠·͍ͬͯΔՄೳੑ͕͋ΔͨΊɺ
    InterfaceAdapterͳ͠ͷ֎෦ΠϯλʔϑΣΠεͷΑ͏ͳҐஔ͚ͮʹͳΔͱߟ͑ศ্ٓ̎৭Ͱද͍ͯ͠·
    ͢ɻ
    • ࣮ࡍʹ͸TwitterAPIClientͳͲ͕ϥΠϒϥϦʹΑͬͯந৅Խ͞Ε͍ͯΔ৔߹΋͋Γɺͦ͜ʹΠϯλʔϑΣ
    ΠεΛ଍͢ͱ৑௕ʹͳΓ·͢͠ɺͦ͏Ͱͳ͍৔߹΋ϏδωεϩδοΫͱ͸RepositoryΠϯλʔϑΣΠε
    Ͱ҆શʹ੾Γ཭͞Ε͍ͯΔͨΊɺ͜͜Ͱ͸ඞͣ͠΋ΠϯλʔϑΣΠεΛ৽ͨʹ༻ҙ͢Δඞཁ͸ͳ͍ͱߟ
    ͍͑ͯ·͢ɻ
    • ̐૚Ͱ࣮૷͢ΔͳΒDataSource͸ΠϯλʔϑΣΠεΞμϓλ(྘)Ͱ͢ͷͰɺTwitterAPIClientͷinterface
    Λ༻ҙ͢Ε͹֎෦ΠϯλʔϑΣΠε(੨)Λ஌Βͳͯ͘΋Α͘ͳΓ·͢ɻ
    • ৗʹ෼཭͢Δͱ֎෦ΠϯλʔϑΣΠε༻ͷσʔλܕͷӅṭ΋ඞཁͳͷͰେมͰ͕͢ɺDataSource͕ෳ
    ࡶʹͳ͖ͬͯͯɺ֎෦ΠϯλʔϑΣΠεͱͷґଘΛബͨ͘͘͠ͳͬͨΒ෼཭͢Δ΄͏͕͍͍Ͱ͠ΐ͏ɻ
    DataSource
    (InterfaceAdapter)
    TwitterAPIDat
    aSource

    View full-size slide