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
3
2k
VIPER Architecture から学ぶ Dependency Injection
iOS Test Night #5 - connpass
https://testnight.connpass.com/event/59283/
star__hoshi
July 26, 2017
Tweet
Share
More Decks by star__hoshi
See All by star__hoshi
大統一ロガーを利用したサービス開発
starhoshi
0
2.9k
Komerco-コメルコ-を支える技術
starhoshi
4
5.9k
実践 Cloud Functions for Firebase
starhoshi
7
5.6k
個人アプリでレビューを高くするためにやっていること
starhoshi
2
1.7k
個人開発を加速させるツール群
starhoshi
54
22k
fastlane 勉強会
starhoshi
0
720
学校の iOS 端末事情
starhoshi
0
2.2k
iOS が fastlane なら Android も fastlane に乗ってみては?
starhoshi
0
2.8k
iOS 開発での Pull Request と テストカバレッジの連携
starhoshi
4
3.1k
Other Decks in Technology
See All in Technology
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
0
150
MLOps の現場から
asei
6
630
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
150
なぜCodeceptJSを選んだか
goataka
0
160
非機能品質を作り込むための実践アーキテクチャ
knih
3
950
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
160
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
260
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
170
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
840
Featured
See All Featured
Designing for Performance
lara
604
68k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
BBQ
matthewcrist
85
9.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
KATA
mclloyd
29
14k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
We Have a Design System, Now What?
morganepeng
51
7.3k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
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
Ҏ্