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

最適な設計でアプリを作る

 最適な設計でアプリを作る

CAMPFIRE iOS #1での発表資料です。
https://yj-meetup.connpass.com/event/51735/
#yjcamp

Tatsuya Tanaka

March 16, 2017
Tweet

More Decks by Tatsuya Tanaka

Other Decks in Technology

Transcript

  1. ࠷దͳઃܭͰ
    ΞϓϦΛ࡞Δ
    ాத ୡ໵ (@tattn)

    View full-size slide

  2. • Yahoo!৐׵Ҋ಺
    • iOSΞϓϦΤϯδχΞ
    • 2016೥৽ଔ
    • Github: @tattn
    • Qiita: @tattn
    • Twitter: @tanakasan2525
    ాத ୡ໵

    View full-size slide

  3. try! Swift ʹࢀՃ͠·͔ͨ͠ʁ

    View full-size slide

  4. try! Swift ʹߦ͖ͬͯ·ͨ͠
    Yahoo! JAPAN Tech Blog
    https://techblog.yahoo.co.jp/
    try! Swift Tokyo 2017 ʹڠࢍ͠·ͨ͠
    https://techblog.yahoo.co.jp/ios/try_swift_2017/
    try! Swift Tokyo 2017 ͷϋοΧιϯʹࢀՃ͠·ͨ͠
    https://techblog.yahoo.co.jp/ios/try_swift_2017_hack/

    View full-size slide

  5. ࣭໰
    օ͞Μ͸ͲͷΑ͏ͳΞʔΩςΫνϟͰ

    ΞϓϦΛ࡞͍ͬͯ·͔͢ʁ
    • MVC
    • MVP
    • MVVM
    • Flux
    • VIPER
    • Clean Architecture

    View full-size slide

  6. ࣭໰
    ͲͷΑ͏ͳج४Ͱ

    ͦͷΞʔΩςΫνϟΛબͼ·͔ͨ͠ʁ

    View full-size slide

  7. ΋͠΋ɺͦͷΞʔΩςΫνϟΛ
    • ࿩୊ʹͳ͔ͬͯͨΒ
    • ͳΜ͔ੌͦ͏͔ͩΒ
    ͷΑ͏ͳཧ༝ͰબΜͰ͍Δ/બ΅͏ͱ͍ͯ͠Δ৔߹͸


    ͥͻվΊͯߟ͑ͯΈ·͠ΐ͏
    (ᐆດͳཧ༝)

    View full-size slide

  8. try! Swift 2017 - 1೔໨

    View full-size slide

  9. σʔλϨΠϠΛ෼཭͢Δ
    Minimum

    Viable

    Architecture
    https://www.slideshare.net/RandyShoup/minimum-viable-
    architecture-good-enough-is-good-enough-in-a-startup
    Minimum Viable Architecture 

    -- Good Enough is Good Enough in a Startup
    http://www.kavistechnology.com/blog/minimal-viable-architecture/
    “ඞཁ࠷খݶΞʔΩςΫνϟ”

    View full-size slide

  10. “What we need is a balance of speed to market
    and architecture. What we need is a Minimal
    Viable Architecture (MVA).” — Randy Shoup
    ࢲ͕ͨͪඞཁͱ͍ͯ͠Δͷ͸
    • ࢢ৔౤ೖͷεϐʔυͱΞʔΩςΫνϟͷόϥϯεͩɻ
    • ඞཁ࠷খݶͷΞʔΩςΫνϟͩɻ
    ελʔτΞοϓͰͳ͘ͱ΋ಉ͜͡ͱ͕ݴ͑Δ͸ͣ

    View full-size slide

  11. ྫ͑͹ɺ

    ҋӢʹ Clean Architecture Λಋೖ͢Δ

    View full-size slide

  12. protocol FeedRepositoryOutput: class {
    func receive(feeds: [Feed])
    }
    class FeedRepository: FeedDataStoreOutput {
    private let dataStore: FeedDataStore
    weak var output: FeedRepositoryOutput?
    init(dataStore: FeedDataStore, output: FeedRepositoryOutput?) { … }
    func getFeeds() {
    dataStore.getFeeds()
    }
    }
    extension FeedRepository: FeedDataStoreOutput {
    func receive(feeds: [Feed]) {
    output?.receive(feeds: feeds)
    }
    }
    Repository patternͷྫ

    View full-size slide


  13. ΋͠΋Clean ArchitectureΛ

    ಋೖ͍ͯ͠ͳ͔ͬͨΒ…

    View full-size slide

  14. Clean ArchitectureΛಋೖ͍ͯ͠ͳ͚Ε͹
    Swift × I/F = Protocol
    protocol FeedRepository {
    var output: FeedRepositoryOutput? { get set }
    func getFeeds()
    }
    extension FeedDataStore: FeedRepository { … }
    ※ͦ΋ͦ΋͜Μͳ͜ͱ͸͠ͳ͍͸ͣͳͷͰগ͠ແ஡ͳྫͰ͢ɻ

    View full-size slide

  15. RepositoryͱDataStore
    ͜ΕΒΛ෼͚ΔϝϦοτ͕׆͖Δͷ͸
    • ௨৴orΩϟογϡ͕͋Δ৚݅Ͱ੾ΓସΘΔ
    • ৚݅ʹΑͬͯ࢖͏API͕มΘΔ
    ͳͲͷ࢓༷͕සൟʹଘࡏ͢Δ৔߹ͩͱࢥ͍·͢

    View full-size slide

  16. ແҙຯͳίʔυͷྔ࢈
    ઌఔͷΑ͏ͳίʔυ͕ྔ࢈͞ΕΔΑ͏ͳΞϓϦʹ͸

    ຊ౰ʹ Clean Architecture ͸ඞཁͩͬͨͷͰ͠ΐ͏͔ʁ
    ෆཁͩͱࢥ͍·͢ɻ

    View full-size slide

  17. Ͱ͸Ͳ͏΍ͬͯઃܭΛ

    બͿ/ߟ͑Δͷ͔

    View full-size slide

  18. ·ͣ͸νʔϜͰ࿩͠߹ͬͯΈ·͠ΐ͏

    View full-size slide

  19. ͳͥઃܭํ਑ΛऔΓܾΊΔͷ͔
    • ࣮૷ํ๏ͷଐਓԽΛ๷͙
    • ςελϏϦςΟͷ୲อ
    • ࢓༷มߋ͠΍͘͢͢Δ
    • etc…
    ଞʹ΋৭ʑ͋Δͱࢥ͍·͢

    View full-size slide

  20. େࣄʹ͍ͨ͜͠ͱΛܾΊΔ
    ΞʔΩςΫνϟʹ͸τϨʔυΦϑ͕͋Γ·͢
    ͦΕΛຬͨ͢ઃܭΛબͿ
    େࣄʹ͍ͨ͜͠ͱ (ධՁ࣠) ΛܾΊͯ

    View full-size slide

  21. ઃܭ͸ڞ௨ݴޠ
    ઃܭ͸ ϓϩδΣΫτͷڞ௨ݴޠ
    (ͪͳΈʹɺClean ArchitectureͷఏএऀͷRobert Martin͸

    ઃܭ͸ “Intent (ҙਤ)” ͩͱߟ͍͑ͯΔΑ͏Ͱ͢)
    ϝϯόʔ͕ೲಘ͢Δઃܭʹ͢Δͷ΋େࣄ
    https://www.infoq.com/news/2013/07/architecture_intent_frameworks

    View full-size slide

  22. ݏ͍ͳݴޠ͸࢖͍ͨ͘ͳ͍Ͱ͢ΑͶ
    http://stackoverflow.com/insights/survey/2016

    View full-size slide

  23. ࣮ࡍʹ౰ͯ͸Ίͯߟ͑ͯΈΔ
    ༷ʑͳΞʔΩςΫνϟΛ

    ࣗ෼ͨͪͷΞϓϦʹద༻͢ΔͱͲ͏ͳΔͷ͔Λ

    ίʔυϨϕϧͰߟ͑ͯΈΔ

    View full-size slide

  24. ࣮ࡍʹ౰ͯ͸Ίͯߟ͑ͯΈΔ
    struct MyApp: MVP { … }
    struct MyApp: Flux { … }
    struct MyApp: CleanArchitecture { … }
    struct MyApp: MVVM, VIPER {}
    ΋͔͢͠Δͱ

    ͦͷΞϓϦʹ͸͜Ε͕Ϛον͢Δ͔΋ʁ

    View full-size slide

  25. ࡞ͬͯΈͳ͖Ό෼͔Μͳ͍
    ࣮ࡍʹίʔυΛॻ͍ͯΈͯ

    ؾ͕෇͘͜ͱͬͯΑ͋͘Γ·͢ΑͶʁ
    1ը໘ͷϞοΫ͚ͩͰ΋

    ࣮૷ͯ͠ΈΔͱ

    Կ͔ݟ͑ͯ͘Δ͔΋͠Ε·ͤΜ

    View full-size slide

  26. ิ଍঺հ
    ATAM 

    (Architecture Tradeoff Analysis Method)
    ΞʔΩςΫνϟτϨʔυΦϑ෼ੳ๏
    ࣮ફιϑτ΢ΣΞΞʔΩςΫνϟ

    Ͱ ঺հ͞Ε͍ͯΔΒ͍͠Ͱ͢

    View full-size slide

  27. ࠷ޙʹ
    ઃܭʹର͢Δߟ͑ํվળͷ

    ͖͔͚ͬʹͳΕ͹޾͍Ͱ͢

    View full-size slide

  28. ʘYahoo!৐׵Ҋ಺ ͥͻ࢖ͬͯͶʗ
    ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠
    @tattn

    View full-size slide