Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
VIPER Architecture から学ぶ Dependency Injection
Search
star__hoshi
July 26, 2017
Technology
2.3k
3
Share
VIPER Architecture から学ぶ Dependency Injection
iOS Test Night #5 - connpass
https://testnight.connpass.com/event/59283/
star__hoshi
July 26, 2017
More Decks by star__hoshi
See All by star__hoshi
大統一ロガーを利用したサービス開発
starhoshi
0
3.3k
Komerco-コメルコ-を支える技術
starhoshi
4
6.1k
実践 Cloud Functions for Firebase
starhoshi
7
5.9k
個人アプリでレビューを高くするためにやっていること
starhoshi
2
1.8k
個人開発を加速させるツール群
starhoshi
54
22k
fastlane 勉強会
starhoshi
0
870
学校の iOS 端末事情
starhoshi
0
2.4k
iOS が fastlane なら Android も fastlane に乗ってみては?
starhoshi
0
3k
iOS 開発での Pull Request と テストカバレッジの連携
starhoshi
4
3.4k
Other Decks in Technology
See All in Technology
開発を止めない CI/CD ~CI Visibilityによる継続的最適化~
pensuke628
0
220
Javaコミュニティをもっと楽しむための9箇条
takasyou
0
760
Spring AI × MCP 入門〜AIエージェントへのツール公開、境界設計から始める最小構成 〜
yuyamiyamoto
0
190
最低限これだけ押さえれ大丈夫_Claude Enterprise/Team企業展開ガバナンス入門
tkikuchi
1
560
プラットフォームエンジニア ワークショップ/ platform-workshop
databricksjapan
0
140
TypeScript Compiler APIとPHP-Parserを活用し、TypeScriptとPHPで型を共有する
shuta13
0
270
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.7k
大規模災害時でも高い信頼性を維持するアプリケーション基盤の実現/nikkei-tech-talk46
nikkei_engineer_recruiting
0
120
探して_入れて_作って_使う_Agent_Skills___LT.pdf
peintangos
2
100
権限管理設計を完全に理解した
rsugi
2
240
さきさん文庫の書籍ができるまで
sakiengineer
0
320
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.8k
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
930
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
590
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
The Limits of Empathy - UXLibs8
cassininazir
1
340
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
300
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
The Language of Interfaces
destraynor
162
26k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
220
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
199
74k
Everyday Curiosity
cassininazir
0
220
Transcript
VIPER Architecture ͔ΒֶͿ Dependency Injection iOS Test Night #5
ࣗݾհ • ຊ໊: ݈հ • Github: starhoshi • Twitter: @star__hoshi
• Classi גࣜձࣾ • -> 8/1 ͔Β ʁʁʁ
VIPER ͷ Router ʹ͍ͭͯ IUUQTDIFFTFDBLFMBCTDPNCMPHJPTQSPKFDU BSDIJUFDUVSFVTJOHWJQFS
ͬ͘͟Γ VIPER • View • Interactor • Presenter • Entity
• Router
ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business
Logic) • Presenter - View ͱ Interactor Λհ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection
ͬ͘͟Γ VIPER • View - UIViewController • Interactor - UseCase(Business
Logic) • Presenter - View ͱ Interactor Λհ • Entity - Data Structure • Router - ը໘ભҠͱ Dependency Injection
Router ͷׂ • ը໘ભҠ • ը໘ભҠͱ Dependency Injection
͜Μͳ͔Μ͡ IUUQTDIFFTFDBLFMBCTDPNCMPHJPTQSPKFDU BSDIJUFDUVSFVTJOHWJQFS
͕࣌ؒͳ͍ͷͰ ཧղ͘͢͢͠ΔͨΊ View, Presenter, Router ͚ͩݟ͍͖ͯ·͢
View protocol UserView: class { var presenter: UserPresentation { get
} init(presenter: UserPresentation) } final class UserViewController: UIViewController, UserView { let presenter: UserPresentation init(presenter: UserPresentation) { self.presenter = presenter } }
Presenter protocol UserPresentation: class { var router: UserWireframe { get
} init(router: UserWireframe) } final class UserPresenter: UserPresentation { let router: UserWireframe init(router: UserWireframe) { self.router = router } }
Router protocol UserWireframe: class { static func assembleModule() -> UIViewController
} final class UserRouter: UserWireframe { static func assembleModule() -> UIViewController { let router = UserRouter() let presenter = UserPresenter(router: router) let view = UserViewController(presenter: presenter) return view } }
ؔੑ • நʹґଘ͍ͯ͠Δ • ͦΕͧΕ͕ Protocol Λ࣮͠ɺ Protocol ʹґଘ͍ͯ͠Δ •
Router ͚͕ͩ۩ΫϥεΛ Initialize ͍ͯ͠Δ • Router Ͱ DI ͍ͯ͠Δʂ
DI ͷୈҰา final class UserPresenter: UserPresentation { let router: UserWireframe
init(router: UserWireframe) { self.router = router } } final class UserPresenter: UserPresentation { let router: UserWireframe init() { self.router = UserRouter() } } ❌ ⭕
Կ͕خ͍͠ͷ͔
ςετ͕ॻ͖͘͢ͳͬͨ • Protocol ʹͷΈґଘ͍ͯ͠Δ • Mock ΫϥεΛ࡞ΕΔ • ґଘؔͷগͳ͍ Testable
ͳΞʔΩςΫνϟʹ • ଞͷΞʔΩςΫνϟͰԠ༻Ͱ͖Δ
ςετίʔυ class UserPresenterSpec: QuickSpec { override func spec() { let
router = MockUserRouter() let presenter = UserPresenter(router: router) describe("viewDidLoad") { beforeEach { presenter.viewDidLoad() } it("…") { … } } } }
͖ͬ͞ͷίʔυ • ͍Ζ͍ΖંͬͯΔ • Presenter ͔Β View ʹ͑ΒΕͳ͍ͱ͔ • Router
͕ը໘ભҠͰ͖ͳ͍ͱ͔ • ͦͦίϯύΠϧ௨Βͳ͍
ਅ໘ʹ VIPER ͨ͠ίʔυ IUUQTHJUIVCDPNTUBSIPTIJ%FWJDF8BMMQBQFS
AppStore ʹग़ͯΔ
None
https://iosdc.jp/2017/node/1543 Stub ͱ Mock ͷҧ͍ɺͪΌΜ ͱཧղͰ͖͍ͯ·͔͢ʁ
VIPER Architecture ͔ΒֶͿ Dependency Injection
Ҏ্