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

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

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

0620564f0125b8b3b7f4fe40c10b8b4e?s=128

Tatsuya Tanaka

March 16, 2017
Tweet

Transcript

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

  2. • Yahoo!৐׵Ҋ಺ • iOSΞϓϦΤϯδχΞ • 2016೥৽ଔ • Github: @tattn •

    Qiita: @tattn • Twitter: @tanakasan2525 ాத ୡ໵
  3. try! Swift ʹࢀՃ͠·͔ͨ͠ʁ

  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/
  5. ࣭໰

  6. ࣭໰ օ͞Μ͸ͲͷΑ͏ͳΞʔΩςΫνϟͰ
 ΞϓϦΛ࡞͍ͬͯ·͔͢ʁ • MVC • MVP • MVVM •

    Flux • VIPER • Clean Architecture
  7. ࣭໰ ͲͷΑ͏ͳج४Ͱ
 ͦͷΞʔΩςΫνϟΛબͼ·͔ͨ͠ʁ

  8. ΋͠΋ɺͦͷΞʔΩςΫνϟΛ • ࿩୊ʹͳ͔ͬͯͨΒ • ͳΜ͔ੌͦ͏͔ͩΒ ͷΑ͏ͳཧ༝ͰબΜͰ͍Δ/બ΅͏ͱ͍ͯ͠Δ৔߹͸
 
 ͥͻվΊͯߟ͑ͯΈ·͠ΐ͏ (ᐆດͳཧ༝)

  9. try! Swift 2017 - 1೔໨

  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/ “ඞཁ࠷খݶΞʔΩςΫνϟ”
  11. “What we need is a balance of speed to market

    and architecture. What we need is a Minimal Viable Architecture (MVA).” — Randy Shoup ࢲ͕ͨͪඞཁͱ͍ͯ͠Δͷ͸ • ࢢ৔౤ೖͷεϐʔυͱΞʔΩςΫνϟͷόϥϯεͩɻ • ඞཁ࠷খݶͷΞʔΩςΫνϟͩɻ ελʔτΞοϓͰͳ͘ͱ΋ಉ͜͡ͱ͕ݴ͑Δ͸ͣ
  12. ྫ͑͹ɺ
 ҋӢʹ Clean Architecture Λಋೖ͢Δ

  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ͷྫ
  14. ΋͠΋Clean ArchitectureΛ
 ಋೖ͍ͯ͠ͳ͔ͬͨΒ…

  15. Clean ArchitectureΛಋೖ͍ͯ͠ͳ͚Ε͹ Swift × I/F = Protocol protocol FeedRepository {

    var output: FeedRepositoryOutput? { get set } func getFeeds() } extension FeedDataStore: FeedRepository { … } ※ͦ΋ͦ΋͜Μͳ͜ͱ͸͠ͳ͍͸ͣͳͷͰগ͠ແ஡ͳྫͰ͢ɻ
  16. RepositoryͱDataStore ͜ΕΒΛ෼͚ΔϝϦοτ͕׆͖Δͷ͸ • ௨৴orΩϟογϡ͕͋Δ৚݅Ͱ੾ΓସΘΔ • ৚݅ʹΑͬͯ࢖͏API͕มΘΔ ͳͲͷ࢓༷͕සൟʹଘࡏ͢Δ৔߹ͩͱࢥ͍·͢

  17. ແҙຯͳίʔυͷྔ࢈ ઌఔͷΑ͏ͳίʔυ͕ྔ࢈͞ΕΔΑ͏ͳΞϓϦʹ͸
 ຊ౰ʹ Clean Architecture ͸ඞཁͩͬͨͷͰ͠ΐ͏͔ʁ ෆཁͩͱࢥ͍·͢ɻ

  18. Ͱ͸Ͳ͏΍ͬͯઃܭΛ
 બͿ/ߟ͑Δͷ͔

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

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

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

  22. ઃܭ͸ڞ௨ݴޠ ઃܭ͸ ϓϩδΣΫτͷڞ௨ݴޠ (ͪͳΈʹɺClean ArchitectureͷఏএऀͷRobert Martin͸
 ઃܭ͸ “Intent (ҙਤ)” ͩͱߟ͍͑ͯΔΑ͏Ͱ͢)

    ϝϯόʔ͕ೲಘ͢Δઃܭʹ͢Δͷ΋େࣄ https://www.infoq.com/news/2013/07/architecture_intent_frameworks
  23. ݏ͍ͳݴޠ͸࢖͍ͨ͘ͳ͍Ͱ͢ΑͶ http://stackoverflow.com/insights/survey/2016

  24. ࣮ࡍʹ౰ͯ͸Ίͯߟ͑ͯΈΔ ༷ʑͳΞʔΩςΫνϟΛ
 ࣗ෼ͨͪͷΞϓϦʹద༻͢ΔͱͲ͏ͳΔͷ͔Λ
 ίʔυϨϕϧͰߟ͑ͯΈΔ

  25. ࣮ࡍʹ౰ͯ͸Ίͯߟ͑ͯΈΔ struct MyApp: MVP { … } struct MyApp: Flux

    { … } struct MyApp: CleanArchitecture { … } struct MyApp: MVVM, VIPER {} ΋͔͢͠Δͱ
 ͦͷΞϓϦʹ͸͜Ε͕Ϛον͢Δ͔΋ʁ
  26. ࡞ͬͯΈͳ͖Ό෼͔Μͳ͍ ࣮ࡍʹίʔυΛॻ͍ͯΈͯ
 ؾ͕෇͘͜ͱͬͯΑ͋͘Γ·͢ΑͶʁ 1ը໘ͷϞοΫ͚ͩͰ΋
 ࣮૷ͯ͠ΈΔͱ
 Կ͔ݟ͑ͯ͘Δ͔΋͠Ε·ͤΜ

  27. ิ଍঺հ ATAM 
 (Architecture Tradeoff Analysis Method) ΞʔΩςΫνϟτϨʔυΦϑ෼ੳ๏ ࣮ફιϑτ΢ΣΞΞʔΩςΫνϟ
 Ͱ

    ঺հ͞Ε͍ͯΔΒ͍͠Ͱ͢
  28. ࠷ޙʹ ઃܭʹର͢Δߟ͑ํվળͷ
 ͖͔͚ͬʹͳΕ͹޾͍Ͱ͢

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