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
Dependency Injection by Aadithya at SwiftDelhi
Search
Swift India
July 16, 2017
Programming
0
57
Dependency Injection by Aadithya at SwiftDelhi
Dependency Injection by Aadithya at SwiftDelhi
Swift India
July 16, 2017
Tweet
Share
More Decks by Swift India
See All by Swift India
Network Layer Abstraction
swiftindia
0
100
Efficient JSON to Object Parsing
swiftindia
0
79
Sign In with Apple
swiftindia
0
89
Furlenco's AR Journey
swiftindia
0
75
Image processing using Core Image and Metal
swiftindia
0
150
Combine - Diving into Apple’s Reactive Programming
swiftindia
1
160
Social in Hotstar
swiftindia
0
150
Improving App Launch Time
swiftindia
1
72
Backend Driven UIs
swiftindia
0
83
Other Decks in Programming
See All in Programming
StoreKit2によるiOSのアプリ内課金のリニューアル
kangnux
0
110
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
コーンフレークから始める モデリング会話入門
ogurotakayuki
0
370
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.4k
GitHub Copilotのススメ
marcy731
1
200
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
140
『Railsオワコン』と言われる時代に、なぜブルーモ証券はRailsを選ぶのか
free_world21
0
250
Snowflakeで眠ったデータを起こそう!
estie
0
120
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
270
2 週間で Twitter Bot を作ってみた
contour_gara
0
570
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
1
190
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
8
4.1k
Featured
See All Featured
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Web Components: a chance to create the future
zenorocha
305
41k
The Invisible Customer
myddelton
114
12k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
187
16k
What the flash - Photography Introduction
edds
64
11k
How STYLIGHT went responsive
nonsquared
92
4.8k
Visualization
eitanlees
136
14k
Art, The Web, and Tiny UX
lynnandtonic
289
19k
Documentation Writing (for coders)
carmenintech
60
3.9k
The Power of CSS Pseudo Elements
geoffreycrofte
60
5k
Adopting Sorbet at Scale
ufuk
68
8.6k
Transcript
Dependency Injection Adithya Reddy iOS engineer at UrbanClap
What. Why. How.
What is dependency Injection? It’s a fancy name for a
fairly simple concept.
Is DI used in this code snippet below? NO
What about this? YES
And this? NO
Traditional way: Race car Engine Transmission Piston Shaft Clutch Flywheel
Dependency injection way: Race car Engine Transmission Piston Shaft Clutch
Flywheel
Why use dependency Injection? 3 C’s Clarity Customizability Concerns
Clarity Callers need to know only about one thing, i.e.
initializer init() is clean and not dumped with constructors No unexpected behavior Example: if a new person joins the team, he need not go throught the viewcontroller to find the dependent objects in it. He just needs to look at init and inject.
Customizability Have control over which implementation to use. For example:
I can plug in Engine with FastEngine without worrying much Also, highly useful in testing. X1 in debug mode and X2 in release mode.
Concerns Race car is just a race car. Need not
worry about the configuration of other parts. Specific purposes lying in each component Allows composing instead of subclassing
Constructor injection vs Setter injection Constructor injection : use when
values dont change Setter injection : use when required. When you want to set the dependencies via properties
How to setup and use dependency injection? Now, I will
demonstrate how to integrate the Typhoon framework to achieve DI. Concept of Assemblies
Coming back… Now… you must be able to answer why
the code snippet below doesnt confirm to DI...
Why does this confirm to DI?
And finally, why doesnt this confirm to DI?