SlideShare a Scribd company logo
1 of 33
Download to read offline
Ƅ Rekimoto Lab. at University of Tokyo
(Samura Lab. at Akashi-NCT)
Enginner at Wantedly, Inc.
Mentor at Life is Tech, Inc.
Ruby
Ruby on Rails
JavaScript
Android
Design
Others
Skill Ratio
Depdendency
Injection
依 存 性 注 入
ディペンデンシー・インジェクション
依存性の注入とは、コンポーネント間の依存関係を
プログラムのソースコードから排除し、
外部の設定ファイルなどで注入できるようにする
ソフトウェアパターンである。
依存性の注入 - Wikipedia
共通 component
ふつうのばあい
共通 component
ふつうのばあい
直接参照している
(global 変数,new など)
共通 component
ふつうのばあい
component の機能が少ない…
拡張しよう!
共通 component
ふつうのばあい
_人人人人人人人人_
> 突然の密結合 <
 ̄Y^Y^Y^Y^Y^Y^Y ̄
共通 component
DI する場合
インタフェースを参照する
共通 component
DI する場合
どの実態を利用するか
○ DI コンテナに記述
共通 component
DI のメリット
ここは単体テストで OK
共通 component の
モック
DI のメリット
mock に差し替えると
テストが容易に!
Android
DI をつかおう
JavaScript
Android
DI をつかおう
Dagger2
Android における DI
Sign in
遷移
tweet 取得
Android における DI
Sign in
遷移
tweet 取得
インスタンス変数に保持してると…
○ ライフサイクルに巻き込まれて死ぬ
Android における DI
Sign in
遷移
tweet 取得
DI コンテナ
Android における DI
Sign in
遷移
tweet 取得
DI コンテナ
DI コンテナが User を保持するので
ライフサイクルに巻き込まれない!
DI をつかおう
JavaScript
Browserify
JavaScript における DI
グローバルオブジェクト(window/global)
JavaScript における DI
グローバルオブジェクト(window/global)
_人人人人人人人人人_
> グローバル汚染 <
 ̄Y^Y^Y^Y^Y^Y^Y^Y ̄
JavaScript における DI
グローバルオブジェクト(window/global)
JavaScript における DI
グローバルオブジェクト(window/global)DI コンテナに押し込めて
グローバル汚染を防止
まとめ
DIでグローバル汚染の防止
DIでテスタビリティ向上
DIでモジュールの疎結合化
Android では…
Dagger / Dagger2
JavaScript では…
Browserify / ECMAScript 6
Do you know Dependency Injection ?
Do you know Dependency Injection ?
Do you know Dependency Injection ?

More Related Content

Viewers also liked

Entrepreneurial learning carltonbolling
Entrepreneurial learning carltonbollingEntrepreneurial learning carltonbolling
Entrepreneurial learning carltonbolling
circle1315
 

Viewers also liked (19)

Functional Dependency Injection in C#
Functional Dependency Injection in C#Functional Dependency Injection in C#
Functional Dependency Injection in C#
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
Inversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best PracticeInversion of Control - Introduction and Best Practice
Inversion of Control - Introduction and Best Practice
 
IoC and Mapper in C#
IoC and Mapper in C#IoC and Mapper in C#
IoC and Mapper in C#
 
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
Eight Signs Your Marketing Content Is Being Wasted, Ignored, Exploited...Or W...
 
Menú de ajustes en word press
Menú de ajustes en word pressMenú de ajustes en word press
Menú de ajustes en word press
 
Sljuncana mafija
Sljuncana mafijaSljuncana mafija
Sljuncana mafija
 
Entrepreneurial learning carltonbolling
Entrepreneurial learning carltonbollingEntrepreneurial learning carltonbolling
Entrepreneurial learning carltonbolling
 
Marketing Channels 101
Marketing Channels 101Marketing Channels 101
Marketing Channels 101
 
Boletim (1)
Boletim (1)Boletim (1)
Boletim (1)
 
外匯交易簡介
外匯交易簡介外匯交易簡介
外匯交易簡介
 
Entrepreneurial Lessons 2012
Entrepreneurial Lessons 2012Entrepreneurial Lessons 2012
Entrepreneurial Lessons 2012
 
Travel Turbulence? Apps to the Rescue!
Travel Turbulence? Apps to the Rescue!Travel Turbulence? Apps to the Rescue!
Travel Turbulence? Apps to the Rescue!
 
Ept1 unidad 2
Ept1 unidad 2Ept1 unidad 2
Ept1 unidad 2
 
Новый взгляд на визуализацию информации
Новый взгляд на визуализацию информацииНовый взгляд на визуализацию информации
Новый взгляд на визуализацию информации
 
Is the future of local media hyperlocal?
Is the future of local media hyperlocal?Is the future of local media hyperlocal?
Is the future of local media hyperlocal?
 
Independent Chairman - Research Spotlight
Independent Chairman - Research SpotlightIndependent Chairman - Research Spotlight
Independent Chairman - Research Spotlight
 
Europees Hof zet eerste stap in dispuut onverdoofd slachten
Europees Hof zet eerste stap in dispuut onverdoofd slachtenEuropees Hof zet eerste stap in dispuut onverdoofd slachten
Europees Hof zet eerste stap in dispuut onverdoofd slachten
 
Diffusion of lead user (Presentation)
Diffusion of lead user (Presentation)Diffusion of lead user (Presentation)
Diffusion of lead user (Presentation)
 

Similar to Do you know Dependency Injection ?

Similar to Do you know Dependency Injection ? (11)

FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
FlutterでのWidgetツリーへの状態伝播とアクセス制限の基本戦略
 
簡単AngularJS(関西AngularJS勉強会)
簡単AngularJS(関西AngularJS勉強会)簡単AngularJS(関西AngularJS勉強会)
簡単AngularJS(関西AngularJS勉強会)
 
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
Swiftで説明する「モナド」:Swiftにおける関数型プログラミングの使い方
 
AndroidでDIxAOP
AndroidでDIxAOPAndroidでDIxAOP
AndroidでDIxAOP
 
jjug_night_20161121
jjug_night_20161121jjug_night_20161121
jjug_night_20161121
 
DiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみたDiI/DIコンテナを一から学んでみた
DiI/DIコンテナを一から学んでみた
 
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)アプリでもオブジェクト指向エクササイズ(Potatotips#3)
アプリでもオブジェクト指向エクササイズ(Potatotips#3)
 
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdfソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #2 インターフェイス分離の原則.pdf
 
DI(依存性注入)について
DI(依存性注入)についてDI(依存性注入)について
DI(依存性注入)について
 
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdfソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
ソフトウェア設計原則【SOLID】を学ぶ #3 依存性逆転の原則.pdf
 
[デブサミ2012]趣味と実益の脆弱性発見
[デブサミ2012]趣味と実益の脆弱性発見[デブサミ2012]趣味と実益の脆弱性発見
[デブサミ2012]趣味と実益の脆弱性発見
 

Recently uploaded

Recently uploaded (7)

NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
業務で生成AIを活用したい人のための生成AI入門講座(社外公開版:キンドリルジャパン社内勉強会:2024年4月発表)
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 

Do you know Dependency Injection ?