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 Slide

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

    View Slide

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

    View 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 Slide

  5. ࣭໰

    View Slide

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

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

    View Slide

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

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

    View Slide

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


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

    View Slide

  9. try! Swift 2017 - 1೔໨

    View Slide

  10. σʔλϨΠϠΛ෼཭͢Δ
    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 Slide

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

    View Slide

  12. ྫ͑͹ɺ

    ҋӢʹ Clean Architecture Λಋೖ͢Δ

    View Slide

  13. 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 Slide


  14. ΋͠΋Clean ArchitectureΛ

    ಋೖ͍ͯ͠ͳ͔ͬͨΒ…

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

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

    બͿ/ߟ͑Δͷ͔

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

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

    View Slide

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

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

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

    View Slide

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

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

    View Slide

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

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

    ࣮૷ͯ͠ΈΔͱ

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

    View Slide

  27. ิ଍঺հ
    ATAM 

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

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

    View Slide

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

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

    View Slide

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

    View Slide