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
OOP, Double Dispatch and Visitor Pattern
Search
Akihito Koriyama
May 24, 2024
Technology
2
100
OOP, Double Dispatch and Visitor Pattern
OOPのエッセンスとビジターパターンを使ったディスパッチのデザインパターン。弁護士ドットコム社で紹介。
Akihito Koriyama
May 24, 2024
Tweet
Share
More Decks by Akihito Koriyama
See All by Akihito Koriyama
app-state-diagram
koriym
0
21
BEAR.Sunday 2014-2024
koriym
0
52
イベント駆動コンテンツ (a.k.a Webアプリケーションの効率を再定義するBEAR.Sundayの分散キャッシングフレームワーク)
koriym
4
6.9k
Unconf: RWA読書会
koriym
0
510
REST 6+4の制約
koriym
2
2.7k
RESTful Web API 読書会 #1
koriym
3
280
RESTの力 / The Power of REST
koriym
10
7.4k
全てを結ぶ力 (2019)
koriym
3
840
REST 6+4=9の制約
koriym
3
1k
Other Decks in Technology
See All in Technology
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
13k
サイバーセキュリティと認知バイアス:対策の隙を埋める心理学的アプローチ
shumei_ito
0
390
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.5k
『Firebase Dynamic Links終了に備える』 FlutterアプリでのAdjust導入とDeeplink最適化
techiro
0
120
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
320
Taming you application's environments
salaboy
0
190
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Faster Mobile Websites
deanohume
305
30k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Site-Speed That Sticks
csswizardry
0
28
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
A Philosophy of Restraint
colly
203
16k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Transcript
001 %PVCMF%JTQBUDIBOE 7JTJUPS1BUUFSO "LJIJUP,PSJZBNB
1BSU001ͱखଓܕ 001BOEQSPDFEVSBMUZQFT
-PHJD %BUB
࢛֯ܗͷ໘ੵΛٻΊΔ 'JOEJOHUIFBSFBPGBRVBESBOHMF
-PHJD %BUB < > BYC
-PHJD%BUBΛΔඞཁ͕͋Δ -PHJDOFFETUPLOPX%BUB
"SFB %BUB BYC QVCMJDB QVCMJDC
ΧϓηϧԽͰ͖ͯͳ͍ /PUFODBQTVMBUFE
-PHJD %BUB BYC HFU" JOU HFU# JOU
ΧϓηϧԽͰ͖ͯͳ͍ /PUFODBQTVMBUFE
w 8IZHFUUFSBOETFUUFSNFUIPETBSFFWJM w (FUUFS4FUUFSѱͩɻҎ্ɻ
ΦϒδΣΫτࢦ PCKFDUPSJFOUFE
4IBQF < > BYC
4IBQF < > BYC BSFB JOU
खଓ͖ܕ QSPDFEVSBMUZQF
$MJFOU %BUB BYC B C
5FMM
4IBQF < > BYC BSFB JOU
"TL
$MJFOU %BUB BYC B C
5FMM %POUBTL
5FMMࣗݾنత 5FMMJTTFMGEJTDJQMJOFE
ΧϓηϧԽ FODBQTVMBUJPO
ΦϒδΣΫτࢦ PCKFDUPSJFOUFE
"TL ϩδοΫ͕σʔλͷ֎ʹ͋Δ *O"TL UIFMPHJDJTPVUTJEFUIFEBUB
-PHJD %BUB BYC B C
σʔλߏ͕࿐ग़ %BUBTUSVDUVSFTFYQPTFE
ϧʔϧ͕ͳ͍ /PSVMFT
υϝΠϯ͕ࣝͳ͍ -BDLPGEPNBJOLOPXMFEHF
υϝΠϯශ݂ %%% %PNBJOBOBFNJB %%%
1BSUμϒϧσΟεύον %PVCMFEJTQBUDI
001Ͱ-PHJDͱ%BUBΛ
యܕత001ͰΦϒδΣΫτ͕ -PHJDΛϓϩύςΟʹอ࣋ *OUZQJDBM001 PCKFDUTIPME-PHJDBTBQSPQFSUZ
%BUB -PHJD BYC
7JTJUPSύλʔϯͰ -PHJD͕σʔλΛ๚ -PHJDWJTJUTEBUBPCKFDUJOUIF7JTJUPSQBUUFSO
7JTJUPS %BUB GVODUJPOBDDFQU 7JTJUPSW
σʔλ๚ऀΛར༻ %BUBVTFTWJTJUPST
7JTJUPS %BUB WWJTJU B C
๚ऀʹϩδοΫ͕͋Δ 7JTJUPSTIBWFMPHJD
7JTJUPS %BUB GVODUJPOWJTJU B C SFUVSOB C
7JTJUPSͰ -PHJD͕ϝιουͰ͞ΕΔ *OUIF7JTJUPSQBUUFSO -PHJDJTQBTTFECZNFUIPE
σʔλίϨΫλʔ ਤܗͷࢹ֮Խ όϦσʔγϣϯ %BUBDPMMFDUPST TIBQFWJTVBMJTBUJPO7BMJEBUJPO
ଟ༷ͳ-PHJDͷҰ࣌తͳ๚ %JWFSTF-PHJDUFNQPSBSZWJTJUT
" %BUB #
γϯάϧσΟεύον ࣮ߦͷܾఆ͕୯Ұ 4JOHMFEJTQBUDI TJOHMFEFDJTJPOUPFYFDVUF
" %BUB # BDDFQU WJTJU
μϒϧσΟεύον ࣮ߦͷܾఆ͕̎ճ %PVCMFEJTQBUDI 5XPFYFDVUJPOEFDJTJPOT
ଟॏσΟεύον ࣮ߦͷܾఆ͕ෳճ .VMUJQMFEJTQBUDI .VMUJQMFFYFDVUJPOEFDJTJPOT
QBSU%*ίϯύΠϥͷઃܭ %*DPNQJMFSEFTJHO
Πϯελϯεੜ JOTUBODFDSFBUJPO
%BUB wOFX*OTUBODF wDMBTT/BNF wBSHVNFOUT wBSHVNFOU wTFUUFS.FUIPET wTFUUFS.FUIPE wNFUIPE/BNF wBSHVNFOUT
wBSHVNFOU Dependency
ґଘʹґଘ͕͋Δ %FQFOEFODFVQPOEFQFOEFODF
%BUB wOFX*OTUBODF wDMBTT/BNF wBSHVNFOUT wBSHVNFOU wTFUUFS.FUIPET wTFUUFS.FUIPE wNFUIPE/BNF wBSHVNFOUT
wBSHVNFOU Dependency
7JTJUPSίϯύΠϥͷઃܭ 7JTJUPSDPNQJMFSEFTJHO
ड͚औͬͨΦϒδΣΫτར༻Λ܁Γฦ͢ 3FQFBUSFDFJWFEPCKFDUVTF
w WJTJU%FQFEFODZ w WJTJU/FX*OTOUBDF w WJTJU"SHVNFOUT w WJTJU"SHVNFOU w
WJTJU4FUUFS.FUIPET w WJTJU4FUUFS.FUIPE %BUB w OFX*OTUBODF wDMBTT/BNF wBSHVNFOUT wBSHVNFOU wTFUUFS.FUIPET wTFUUFS.FUIPE wNFUIPE/BNF wBSHVNFOUT wBSHVNFOU Visitor Dependency
4FUUFS.FUIPETͷ߹ 'PS4FUUFS.FUIPET
%BUB SetterMethods public function accept(VisitorInterface $visitor) { $visitor->visitSetterMethods($this->setterMethods); }
w Visitor public function visitSetterMethods( array $setterMethods ) { foreach
($setterMethods as $setterMethod) { $setterMethod->accept($this); } }
7JTJUPSड͚औͬͨΦϒδΣΫτΛ ʑͱεΫϦϓτʹ 5IF7JTJUPSTFOETUIFSFDFJWFEPCKFDUUPUIFTDSJQUDPEF
ෳࡶͳߏͷBDDFQUͱWJTJUΛ܁Γฦ͠ ݁ہ࠷ॳͷίʔϧ͕࠷ऴ݁ՌΛड͚औΔ 3FQFBUFEBDDFQUBOEWJTJUPGDPNQMFYTUSVDUVSFT &WFOUVBMMZUIF fi STUDBMMSFDFJWFTUIF fi OBMSFTVMU
w WJTJU%FQFEFODZ w %BUB w Visitor Dependency
ͦΕͧΕͷϝιου ہॴతͳࣝͱλεΫ͔͠ཁٻ͞Εͳ͍ 0OMZMPDBMLOPXMFEHFBOEUBTLTBSFSFRVJSFE
ෳࡶͳґଘߏΛίϯύΠϥΒͳ͍ $PNQJMFSTBSFVOBXBSFPGDPNQMFYEFQFOEFODZTUSVDUVSFT
ࠓԿΛ͢Δ͔ͱɺ࣍ʹԿΛݺͿ͔ ଞʹؔ৺͕ͳ͍ 8IBUUPEPOPXBOEXIBUUPDBMMOFYU /PUJOUFSFTUFEJOBOZUIJOHFMTF
શମΛΔίϯμΫλʔ͍ͳ͍ /PDPOEVDUPSLOPXTUIFXIPMFTUSVDUVSF
ΦʔέετϨʔγϣϯͰͳ͘ɺίϨΦάϥϑΟʔ $IPSFPHSBQIZ OPUPSDIFTUSBUJPO
σʔλͱϩδοΫΛ͠ɺΦϒδΣΫ τߏͷৄࡉΛΒͣʹ৽͍͠ϩδοΫ Λద༻Ͱ͖ΔσβΠϯύλʔϯ %FTJHOQBUUFSOTUIBUTFQBSBUFEBUBGSPNMPHJDBOE BMMPXOFXMPHJDUPCFBQQMJFEXJUIPVULOPXJOHUIF EFUBJMTPGUIFPCKFDUTUSVDUVSF