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
49
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
54
スクラムガイド輪読会 / changes 2020 Scrum Guide
juve534
0
93
PHPUnitでパラメタライズドテストと例外のテスト / PHPUnit +Parameterized Test
juve534
0
230
レガシーコードに最低限の秩序をもたせる
juve534
2
1.3k
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Side Projects
sachag
452
42k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Code Reviewing Like a Champion
maltzj
520
39k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
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͔Β࠾༻͞ΕΔ