SlideShare a Scribd company logo
1 of 14
SUMMARY OF “DI”
WHESON_LT #1 by @black_bracken
くろわらび
■ Twitter: @black_bracken
■ IN/B2
■ いろんな言語を触っている
■ いろんな趣味を浅く嗜んでいる
■ いろんなゲームを触っている
■ いろんな単位を落としている
■ https://bracken.black/
Ad: PicSorter
■ ← ダウンロード
■ 画像管理用のAndroid app
– Android 8.0以降で動く
■ ディレクトリ分けとか一時ファイルの
扱いで有用かも
■ ソースコード:
https://github.com/blackbracken/PicSorter
DIご存じですか?
DIとは
■ Dependency Injectionの略
– 直訳すると『依存性の注入』
■ デザインパターンの一種
– 簡単の為に今回はクラスベースOOP言語での利用を仮定します
■ 『制御の反転』によるオブジェクトの制御反転
– 制御というより管理に近い気もする
What is “dependency”?
■ (クラスなどからみて)利用するオブジェクトのこと
– 定数しかり他クラスのインスタンスしかり
– 振る舞いがオブジェクトに『依存』している
■ 依存性の注入は依存しているオブジェクトの外部からの注入ともいえる
Code: Not DI
Code: Constructor DI
DIの何が良いのか
■ 振る舞いと、依存の明記を分離出来る
■ コードが表す意味を正しく示しやすくなる
– 『車がエンジンを生み出す』と『車にエンジンを与える』
– どちらかといえば『制御の逆転』のメリットな気がする
■ 契約(インターフェース)さえあればそれに依存する機能の実装が可能に
– 実装を1つ1つ完了させなくて良い
– これはAPIとかでもよくある手法
■ テストがしやすくなる
– これは後述
DIとテスト
■ モック
– テスト用にダミーの値が入ったクラス
– これで依存しているオブジェクトにかかわらずユニットテストが行える
– ネットワークとかだと尚更
Code:Tested with DI
Code:Tester with DI
DIコンテナ
■ DIは外部から依存先を受け取られるようにする
– 即ちどこかから依存先を与える必要がある
■ そういうのを諸々管理して勝手に注入したりしてくれる
■ コードとか出したかったけど時間無さそうなのであきらめた
まとめ ■ DIはまあ言われれば当たり前のパターン
– 言語化したのがえらいと思います

More Related Content

Recently uploaded

境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台
境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台
境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台sundstromkichline246
 
shopee购买发春药【购买网址: GHB1.com】 催情药价格【商城网址: 91miwan.com☆】
shopee购买发春药【购买网址:  GHB1.com】 催情药价格【商城网址:  91miwan.com☆】shopee购买发春药【购买网址:  GHB1.com】 催情药价格【商城网址:  91miwan.com☆】
shopee购买发春药【购买网址: GHB1.com】 催情药价格【商城网址: 91miwan.com☆】mcguirkberthold315
 
20240521_RPALT_kitazaki_v1__________.pdf
20240521_RPALT_kitazaki_v1__________.pdf20240521_RPALT_kitazaki_v1__________.pdf
20240521_RPALT_kitazaki_v1__________.pdfAyachika Kitazaki
 
sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号
sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号
sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号sundstromkichline246
 
微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台
微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台
微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台sundstromkichline246
 
微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发
微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发
微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发sundstromkichline246
 
20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf
20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf
20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf株式会社MonotaRO Tech Team
 
购买官网听话水【购买网址: GHB1.com】 迷幻药货到付款【商城网址: 91miwan.com☆】
购买官网听话水【购买网址:  GHB1.com】 迷幻药货到付款【商城网址:  91miwan.com☆】购买官网听话水【购买网址:  GHB1.com】 迷幻药货到付款【商城网址:  91miwan.com☆】
购买官网听话水【购买网址: GHB1.com】 迷幻药货到付款【商城网址: 91miwan.com☆】cromandougharty
 
失忆方法迷幻药【购买网址: GHB1.com】 拍肩粉货到付款购买【商城网址: 91miwan.com☆】
失忆方法迷幻药【购买网址:  GHB1.com】 拍肩粉货到付款购买【商城网址:  91miwan.com☆】失忆方法迷幻药【购买网址:  GHB1.com】 拍肩粉货到付款购买【商城网址:  91miwan.com☆】
失忆方法迷幻药【购买网址: GHB1.com】 拍肩粉货到付款购买【商城网址: 91miwan.com☆】cromandougharty
 
QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城
QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城
QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城sundstromkichline246
 
QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售
QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售
QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售sundstromkichline246
 

Recently uploaded (11)

境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台
境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台
境外手机卡商城【☆购买网站:fk578.com】【☆购买网址:fk578.com☆】☆☆快手账号交易平台
 
shopee购买发春药【购买网址: GHB1.com】 催情药价格【商城网址: 91miwan.com☆】
shopee购买发春药【购买网址:  GHB1.com】 催情药价格【商城网址:  91miwan.com☆】shopee购买发春药【购买网址:  GHB1.com】 催情药价格【商城网址:  91miwan.com☆】
shopee购买发春药【购买网址: GHB1.com】 催情药价格【商城网址: 91miwan.com☆】
 
20240521_RPALT_kitazaki_v1__________.pdf
20240521_RPALT_kitazaki_v1__________.pdf20240521_RPALT_kitazaki_v1__________.pdf
20240521_RPALT_kitazaki_v1__________.pdf
 
sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号
sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号
sm支付宝号购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】抖音小号自动发号
 
微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台
微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台
微信白号怎么买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul账号交易平台
 
微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发
微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发
微信实名号哪里买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】soul实名账号批发
 
20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf
20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf
20240522 Findy Event ビジネスの構造をアーキテクチャに落とし込みソフトウェアに可変性を注入する.pdf
 
购买官网听话水【购买网址: GHB1.com】 迷幻药货到付款【商城网址: 91miwan.com☆】
购买官网听话水【购买网址:  GHB1.com】 迷幻药货到付款【商城网址:  91miwan.com☆】购买官网听话水【购买网址:  GHB1.com】 迷幻药货到付款【商城网址:  91miwan.com☆】
购买官网听话水【购买网址: GHB1.com】 迷幻药货到付款【商城网址: 91miwan.com☆】
 
失忆方法迷幻药【购买网址: GHB1.com】 拍肩粉货到付款购买【商城网址: 91miwan.com☆】
失忆方法迷幻药【购买网址:  GHB1.com】 拍肩粉货到付款购买【商城网址:  91miwan.com☆】失忆方法迷幻药【购买网址:  GHB1.com】 拍肩粉货到付款购买【商城网址:  91miwan.com☆】
失忆方法迷幻药【购买网址: GHB1.com】 拍肩粉货到付款购买【商城网址: 91miwan.com☆】
 
QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城
QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城
QQ实名号自助购买【☆出售网址:fk578。com☆】【☆购买网址:fk578。com☆】实名微博号购买商城
 
QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售
QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售
QQ实名号如何购买【☆出售网址:fk578点com☆】【☆购买网址:fk578'com☆】免实名手机号出售
 

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Summary of DI