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
DIについて知る / Let's study together DI.
Search
juve534
February 19, 2021
0
48
DIについて知る / Let's study together DI.
DIについて社内勉強会をしたその資料
juve534
February 19, 2021
Tweet
Share
More Decks by juve534
See All by juve534
DMMプラットフォームでプルリクエストのマージ時間を250時間から50時間に減らした話 / Developers Summit 2023
juve534
3
2.3k
CleanArchitecture輪読会 - SOLID原則 - / Clean Architecture Round Reading SOLID
juve534
0
52
スクラムガイド輪読会 / changes 2020 Scrum Guide
juve534
0
92
PHPUnitでパラメタライズドテストと例外のテスト / PHPUnit +Parameterized Test
juve534
0
230
レガシーコードに最低限の秩序をもたせる
juve534
2
1.3k
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Become a Pro
speakerdeck
PRO
24
5k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Transcript
DIʹ͍ͭͯΔ 2021-02-19 ࣾษڧձ @juve534
ࠓ͢͜ͱ • DIʹ͍ͭͯ • DIΛ͏ͱԿ͕ྑ͍ͷ͔
ࠓͤͳ͍͜ͱ • DIίϯςφʹ͍ͭͯ • ࣗৄ͘͠ͳ͍ͨΊ
ग़య : https://qiita.com/fagai/items/bf336e56c5b2bddec749 ͜ͷهࣄΛϕʔεʹਐΊ͍͖ͯ·͢
DIʹ͍ͭͯ
DIʹ͍ͭͯ • Dependency Injectionͷུ • ຊޠʹ༁͢ͱʮґଘੑͷೖʯ • ίϯϙʔωϯτؒͷґଘؔΛϓϩάϥϜ͔Βഉআ͠ɺ֎෦ͷઃఆϑΝΠϧ ͰೖͰ͖Δ͜ͱ •
ग़లɿhttps://ja.wikipedia.org/wiki/ %E4%BE%9D%E5%AD%98%E6%80%A7%E3%81%AE%E6%B3%A8%E5% 85%A5
None
ʮґଘੑʯΛΦϒδΣΫτʹஔ͖͑Δͱ ʮΦϒδΣΫτͷೖʯͱͳΔ
DIͰͳ͍ঢ়ଶΛઌʹΔ • DIͰͳ͍ঢ়ଶɺઌఔͷٯͰߟ͑Εྑ͍ • ґଘੑ͕͋Δঢ়ଶ • etc) ίϯετϥΫλͰΦϒδΣΫτΛੜ͍ͯ͠Δ
DIͰͳ͍ঢ়ଶΛઌʹΔ ΫϥεͰΦϒδΣΫτ ੜ
DIͰͳ͍ঢ়ଶΛઌʹΔ • ClientΫϥε͕ίϯετϥΫλͰੜ͞Ε͍ͯΔ • ClientΫϥεʹґଘͯ͠ɺີ݁߹Ͱ୯ମςετͮ͠Β͍ • ClientΫϥεͷৼΔ͍୲อ͢Δ͜ͱʹͳΔͨΊ
DIͯ͠ΈΔ
DIͯ͠ΈΔ ੜ͞ΕͨΦϒδΣΫτ ΛҾͱ͢Δ ͜͜ಉ͡
DIͯ͠ΈΔ • ίϯετϥΫλͰΦϒδΣΫτΛड͚औΔΑ͏ʹ͢Δ • ͖ͬ͞ͱຆͲมΘΒͳ͍͕ɺ͜ΕʹΑΓϞοΫΛ͑ΔΑ͏ʹ ͳΔ • ϞοΫΛ͑Δ͜ͱͰɺϦΫΤετͷฦΓΛςετͰ͖Δ
DIͯ͠ΈΔ ٖࣅతͳϨεϙϯεΛ ઃఆ͢Δ ݁ՌΛςετ͢Δ
DIͯ͠ΈΔ • ClientΫϥεΛ֎͔Β͢͜ͱͰૄ݁߹ • ίʔυͷΑ͏ʹϞοΫΛ͢͜ͱ͕Մೳ • ϞοΫΛͤΔ͜ͱͰɺ୯ମςετ͕ॻ͖͘͢ͳͬͨ
ߋʹҰาਐΜͰݟΔ
DIͯ͠ΈΔ • ઌఔͷྫͰ֎͔ΒೖͰ͖ΔΑ͏ʹͳ͕ͬͨɺ࣮ମʹґଘͯ͠ ͍Δ • ྫ͑ҧ͏ϥΠϒϥϦΛ͓͏ͱࢥ͏ͱɺΫϥεͷࠩ͠ସ͕͑ ඞཁ • ͜͜ΛநԽ͢Δ͜ͱͰղܾΛਤΔ
DIͯ͠ΈΔ ઌఔΦϒδΣΫτΛड͚औͬͨ ͕ɺ*OUFSGBDFΛड͚औΔΑ͏ʹ ͢Δ *OUFSGBDF͕ҰॹͰ͋Εɺ ࠩ͠ସ͕͑Մೳ
DIͯ͠ΈΔ • InterfaceΛ͏Α͏ʹ͢Δ͜ͱͰநԽʹޭ • நԽ͞Ε͍ͯΔͷͰɺΦϒδΣΫτͷࠩ͠ସ͕͑Մೳ • GuzzleHttpͱCakePHPͷClient྆ํͰಈ͘Α͏ʹ
DIͯ͠ΈΔ • ۩ମతͳྫͱͯ͠ɺϦϚΠϯμʔΛߟ͑Δ • ϦϚΠϯμʔ͕ϝʔϧϓογϡ௨Λͯ͘͠ΕΔͱ͢Δ • ϢʔβͷઃఆʹԠͯ͡Γସ͑Δͱͨ͠߹ • ಉ͡Interfaceʹͯ͠ɺݺͼग़͠Ͱ͍͚ͱ͍͏࣮͕Ͱ͖Δ •
όϦΤʔγϣϯΛInterfaceͰநԽ͠ɺOCPΛҙ࣮ࣝͨ͠Մೳ
͜ͷநԽ·Ͱ͕DIͱݺͿ…Β͍͠
·ͱΊ • DIΛ͏͜ͱͰίʔυΛૄ݁߹ʹ͢Δ͜ͱ͕Ͱ͖Δ • ૄ݁߹ʹ͢Δ͜ͱͰԼهͷϝϦοτ͕ಘ͍͢ • ୯ମςετ͕ॻ͖͍͢ • ίʔυͷࠩ͠ସ͕͑༻ҙ
ࢀߟࢿྉ • ࠷ߴʹΘ͔ΔDIίϯςφ(ಛʹPHPʹϑΥʔΧεͨ͠ • ґଘੑͷೖ - Wikipedia
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠
༨ஊ • ͲͷΦϒδΣΫτΛࠩ͠ࠐΉ͔Λཧ͢Δඞવ͕͋Δ • ίʔυʹࢄΒΔͱཧ͕ͮ͠Β͍ • ͦ͜ͰDIίϯςφͱ͍͏ΈͰҰݩཧ͢Δ • Laravel, SymfonyͰ࠾༻͞Ε͍ͯΔΈ
• CakePHPͰ4.2͔Β࠾༻͞ΕΔ