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
24
BEAR.Sunday 2014-2024
koriym
0
52
イベント駆動コンテンツ (a.k.a Webアプリケーションの効率を再定義するBEAR.Sundayの分散キャッシングフレームワーク)
koriym
4
7.1k
Unconf: RWA読書会
koriym
0
520
REST 6+4の制約
koriym
2
2.7k
RESTful Web API 読書会 #1
koriym
3
280
RESTの力 / The Power of REST
koriym
10
7.5k
全てを結ぶ力 (2019)
koriym
3
860
REST 6+4=9の制約
koriym
3
1.1k
Other Decks in Technology
See All in Technology
Google Cloud で始める Cloud Run 〜AWSとの比較と実例デモで解説〜
risatube
PRO
0
110
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
800
kargoの魅力について伝える
magisystem0408
0
210
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
110
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
110
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
180
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
150
なぜCodeceptJSを選んだか
goataka
0
160
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
840
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
280
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
Featured
See All Featured
Site-Speed That Sticks
csswizardry
2
190
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Designing Experiences People Love
moore
138
23k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
A better future with KSS
kneath
238
17k
Thoughts on Productivity
jonyablonski
67
4.4k
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 UIFMPH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ͷઃܭ %*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