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
94
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
19
BEAR.Sunday 2014-2024
koriym
0
50
イベント駆動コンテンツ (a.k.a Webアプリケーションの効率を再定義するBEAR.Sundayの分散キャッシングフレームワーク)
koriym
4
6.9k
Unconf: RWA読書会
koriym
0
510
REST 6+4の制約
koriym
2
2.6k
RESTful Web API 読書会 #1
koriym
3
280
RESTの力 / The Power of REST
koriym
10
7.4k
全てを結ぶ力 (2019)
koriym
3
830
REST 6+4=9の制約
koriym
3
1k
Other Decks in Technology
See All in Technology
顧客が本当に必要だったもの - パフォーマンス改善編 / Make what is needed
soudai
24
6.7k
Apple/Google/Amazonの決済システムの違いを踏まえた定期購読課金システムの構築 / abema-billing-system
cyberagentdevelopers
PRO
1
210
新卒1年目が向き合う生成AI事業の開発を加速させる技術選定 / ai-web-launcher
cyberagentdevelopers
PRO
7
1.5k
失敗しないOpenJDKの非互換調査
tabatad
0
270
【技術書典17】OpenFOAM(自宅で極める流体解析)2次元円柱まわりの流れ
kamakiri1225
0
210
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
160
CAMERA-Suite: 広告文生成のための評価スイート / ai-camera-suite
cyberagentdevelopers
PRO
3
260
サイバーエージェントにおける生成AIのリスキリング施策の取り組み / cyber-ai-reskilling
cyberagentdevelopers
PRO
2
180
小規模に始めるデータメッシュとデータガバナンスの実践
kimujun
3
560
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
610
大規模データ基盤チームのオンプレTiDB運用への挑戦 / dpu-tidb
cyberagentdevelopers
PRO
1
110
Vueで Webコンポーネントを作って Reactで使う / 20241030-cloudsign-vuefes_after_night
bengo4com
4
2.5k
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
The Pragmatic Product Professional
lauravandoore
31
6.3k
Automating Front-end Workflow
addyosmani
1365
200k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Why Our Code Smells
bkeepers
PRO
334
57k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Scaling GitHub
holman
458
140k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.1k
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ࣗݾنత 5FM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UDI 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