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
learning-cleanarchitecture-in-go
Search
Takashi Matsuyuki
February 28, 2019
Programming
0
150
learning-cleanarchitecture-in-go
Takashi Matsuyuki
February 28, 2019
Tweet
Share
More Decks by Takashi Matsuyuki
See All by Takashi Matsuyuki
新規事業立ち上げ、グロースで きちんと”デリバリー”も"ディスカバリー"も し続けられるアジャイル組織の作り方
applepine1125
2
1.5k
最後に勝つ負け方を知っておく
applepine1125
1
390
評価者を孤独にしない
applepine1125
15
5.6k
"OKR"と"野望"で、 メンバーと組織をアラインメントする
applepine1125
5
940
君たちはどうユーザーと向き合うか
applepine1125
0
370
Self-Organizing Product Development Team: Empowered Output Cycle and Collaborative Culture
applepine1125
0
890
オーナーシップを持ち自己組織化するチームに必要な Engineering Program Managerという役割
applepine1125
2
1.9k
Settlement simulation testing to ensure correct settlement processing
applepine1125
2
2.9k
goはwireでDIする
applepine1125
0
290
Other Decks in Programming
See All in Programming
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Remix on Hono on Cloudflare Workers
yusukebe
1
300
初めてDefinitelyTypedにPRを出した話
syumai
0
420
CSC509 Lecture 12
javiergs
PRO
0
160
Jakarta EE meets AI
ivargrimstad
0
130
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
CSC509 Lecture 13
javiergs
PRO
0
110
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
watsonx.ai Dojo #4 生成AIを使ったアプリ開発、応用編
oniak3ibm
PRO
1
140
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Speed Design
sergeychernyshev
25
620
Scaling GitHub
holman
458
140k
Optimizing for Happiness
mojombo
376
70k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Fireside Chat
paigeccino
34
3k
Documentation Writing (for coders)
carmenintech
65
4.4k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Transcript
Go ͰֶͿClean Architecture ͓·͚: GoΛֶͿͨΊͷ͓͢͢ΊυΩϡϝϯτ
झࢫ(࠷ॳͷఆ) Go 㲗 CA GoΛ௨ͯ͠CAͷཧղΛਂΊΔ CAΛ௨ͯ͠GoͷཧղΛਂΊΔ
झࢫ(ࢿྉ࡞ͬͨ݁Ռ) Go → CA GoΛ௨ͯ͠CAͷཧղΛਂΊΔ CAΛ௨ͯ͠GoͷཧղΛਂΊΔ ޙΖʹ͓·͚Λ͚ͭ·ͨ͠
ΞδΣϯμ • Clean Architectureͱʁ • SOLIDݪଇ • CAͷϨΠϠʔߏ • ϨΠϠʔͷڥքɺӽڥ
• GoͰCA࠾༻͢ΔͱͲ͏ʁ • GoΛษڧ͢ΔͳΒ͜ΕಡΜͲ͚
αϯϓϧΞϓϦέʔγϣϯ TODOΞϓϦΛఆ UserใͱTaskใΛฦ͢APIαʔό ϦϙδτϦ: https://github.com/applepine1125/learning- cleanarchitecture-in-go ઈࢍվળத 13डத
෮श ΞʔΩςΫνϟͱʁ
ΞʔΩςΫνϟͷత ॏཁͳํʹྗ͠ɺৄࡉͷܾఆΛΒͤΔ →มߋʹॊೈͳΞϓϦέʔγϣϯΛ࡞Δ ϏδωεϩδοΫ ํ ϑϨʔϜϫʔΫɺυϥΠό ৄࡉ ॏཁ େখ ଐਓੑ
େখ
෮श Clean Architectureͱʁ
ͳΜ͔͜Μͳਤͷͭ
CAͷతɺಛੑ • ϑϨʔϜϫʔΫඇґଘ • ςετՄೳ • UIඇґଘ • σʔλϕʔεඇґଘ •
֎෦ΤʔδΣϯτඇґଘ →ͭ·ΓৄࡉͱํΛΓ͍͢͠
CAΛߏ͢Δཁૉ • Ϟδϡʔϧείʔϓʹ͓͚Δ5ݪଇ • ίϯϙʔωϯτείʔϓʹ͓͚Δ6ݪଇ • ϨΠϠʔ • ֤ϨΠϠʔͷҙຯɺ •
ϨΠϠʔͷڥքͷҾ͖͔ͨɺӽڥͷ͔ͨ͠
CAΛߏ͢Δݪଇ • Ϟδϡʔϧείʔϓ (SOLIDݪଇ) • ୯Ұͷݪଇ (SRP) • ΦʔϓϯɾΫϩʔζυͷݪଇ (OCP)
• Ϧείϑͷஔݪଇ (LSP) • ΠϯλʔϑΣʔεͷݪଇ (ISP) • ґଘؔٯసͷݪଇ (DIP) ← Ұ൪ॏཁ
CAΛߏ͢Δݪଇ • ίϯϙʔωϯτείʔϓ (ڽूੑ) • ࠶ར༻ɾϦϦʔεՁͷݪଇ (REP) • ดੑڞ௨ͷݪଇ (CCP)
• શ࠶ར༻ͷݪଇ (CRP)
CAΛߏ͢Δݪଇ • ίϯϙʔωϯτείʔϓ (ؔ࿈ੑ) • ඇ॥ґଘؔͷݪଇ (ADP) • ҆ఆґଘͷݪଇ (SDP)
• ҆ఆɾநՁͷݪଇ (SAP)
CAΛߏ͢Δݪଇ • Ϟδϡʔϧείʔϓ • DIP ←Ұ൪ॏཁ • Ϟδϡʔϧείʔϓ • SRP,
OCP, LSP, ISP • ίϯϙʔωϯτείʔϓ(ڽूੑ) • REP, CCP, CRP • ίϯϙʔωϯτείʔϓ(ؔੑ) • ADP, SDP, SAP આ໌͠·͢ ࣗश
SOLIDݪଇ
୯Ұͷݪଇ “ϞδϡʔϧͨͬͨҰͭͷΞΫλʔʹରͯ͠ Λෛ͏͖Ͱ͋Δ”
୯Ұͷݪଇ ϙΠϯτ • มߋ͢Δཧ༝͕ඞͣڞ௨Ͱ͋Εɺ ڞ௨Ϟδϡʔϧͱͯ͠Γग़ͯ͠ྑ͍ ٯʹݴ͏ͱͲ͏ͳΔʁ
ΦʔϓϯɾΫϩʔζυͷݪଇ “ߏཁૉ֦ுʹରͯ͠։͍͍ͯͯɺमਖ਼ʹ ରͯ͠ด͍ͯ͡ͳ͚ΕͳΒͳ͍”
ΦʔϓϯɾΫϩʔζυͷݪଇ ϙΠϯτ • interfaceʹΑͬͯ৽͍͠ػೳΛ؆୯ʹ औΓೖΕΔ͜ͱ͕Ͱ͖Δ • ͋ΔϞδϡʔϧͷมߋͷӨڹ͕ଞͷ ϞδϡʔϧӨڹ͠ͳ͍
Ϧείϑͷஔݪଇ “SܕͷΦϒδΣΫτͷo1ͷ֤ʑʹɺରԠ͢ΔTܕͷΦϒδΣΫτo2͕̍ͭ ଘࡏ͠ɺTΛͬͯఆٛ͞ΕͨϓϩάϥϜPʹରͯ͠o2ͷΘΓʹo1Λ ͬͯPͷৼΔ͍͕มΘΒͳ͍߹STͷੜܕͰ͋Δͱݴ͑Δ”
Ϧείϑͷஔݪଇ ϙΠϯτ • ϞδϡʔϧΛஔՄೳͳঢ়ଶʹ͢Δ ΦʔϓϯɾΫϩʔζυͷݪଇͷ֦ுੑͷ༰ͱҰॹ
ΠϯλʔϑΣʔεͷݪଇ ϙΠϯτ • ຊདྷඞཁͱ͠ͳ͍ͷʹ·Ͱґଘ͠ͳ͍Α͏ ʹɺΠϯλʔϑΣʔεΛڬΜͰૄ݁߹ʹ͢Δ
ґଘؔٯసͷݪଇ • interfaceΛ༻͍ͯґଘؔΛٯసͤ͞Δ 6TFDBTF 3FQPTJUPSZ 42-)BOEMFS %*1ద༻લ %*1ద༻ޙ 6TFDBTF 3FQPTJUPSZ
42-)BOEMFS 3FQPTJUPSZ *OUFSGBDF 42-)BOEMFS *OUFSGBDF
ґଘؔٯసͷݪଇ ϙΠϯτ • มԽ͍͢͠ϞδϡʔϧΛࢀরɺܧঝɺ ΦʔόʔϥΠυɺ໊ࢦ͠Ͱࢀর͠ͳ͍ →CAͰϨΠϠʔΛ·͍ͨͰϞδϡʔϧΛ ࢀর͢Δͱ͖ʹॏཁʂ
CAͷతɺಛੑ • ϑϨʔϜϫʔΫඇґଘ • ςετՄೳ • UIඇґଘ • σʔλϕʔεඇґଘ •
֎෦ΤʔδΣϯτඇґଘ →ݪଇΛར༻͢Ε࣮ݱͰ͖ͦ͏ʁ վΊͯɾɾɾ
CAͷϨΠϠʔߏ
CAͷ֤ϨΠϠʔ • ΤϯςΟςΟ • Ϣʔεέʔε • ΠϯλʔϑΣʔεΞμϓλ • ϑϨʔϜϫʔΫɺυϥΠό
• ΤϯςΟςΟ • Ϣʔεέʔε • ΠϯλʔϑΣʔεΞμϓλ • ϑϨʔϜϫʔΫɺυϥΠό ϙΠϯτ ୯ํґଘͰ͋Δ
CAͷ֤ϨΠϠʔ ґଘ͞Ε͍ͯΔ ԁͷத ԁͷ֎ ґଘ͍ͯ͠Δ
ΤϯςΟςΟ • Ϗδωεࣗମͷ࠷ॏཁϧʔϧΛ·ͱΊͨͷ • γεςϜ͕webΞϓϦέʔγϣϯͱ͍͏ܗଶ Ͱͳ͔ͬͨͱͯ͠ଘࡏ͢Δใ
ΤϯςΟςΟ w ۀʹඞཁͳใ͕ೖͬͨߏମ w ඞཁͳใΛੜ͢ΔͨΊͷϝιου ྫTSDQLHEPNBJOVTFSHP
Ϣʔεέʔε • ΞϓϦέʔγϣϯݻ༗ͷϏδωεϧʔϧ ΛؚΉ • ΤϯςΟςΟͷϏδωεϩδοΫΛΈ߹Θ ͤͯ༻ɺ੍ޚ͢Δ
Ϣʔεέʔε ྫTSDQLHVTFDBTFUBTLJOUFSBDUPSHP w σʔλͷऔಘ SFQPTJUPSZ JOUFSGBDFΛૠ͢ w ӬଓԽ͢ΔͨΊʹUBTLͷใΛͬͯΞϓϦέʔγϣϯݻ༗ͷ σʔλͷܗʹม
ΠϯλʔϑΣʔεΞμϓλ • ϢʔεέʔεɺΤϯςΟςΟ͔ΒDBϑϨʔ ϜϫʔΫͳͲ͕͏ϑΥʔϚοτσʔλΛ ม͢Δ(ͦͷٯવΓ) • ೖྗɺग़ྗɺӬଓԽʹؔ͢ΔϞδϡʔϧ͕ॴ ଐ͢Δ
ΠϯλʔϑΣʔεΞμϓλ ྫTSDQLHJOUFSGBDFUBTLSFQPTJUPSZHP w ӬଓԽͷͨΊʹΫΤϦΛൃߦ͍ͯ͠Δ
ϑϨʔϜϫʔΫɺυϥΠό • ϑϨʔϜϫʔΫπʔϧͳͲͷίʔυͰ ߏ͞Ε͍ͯΔ • WebͷUIͳͲ͜͜
ϑϨʔϜϫʔΫɺυϥΠό ྫTSDQLHJOGSBTRMIBOEMFSHP w EBUBCBTFTRMϥΠϒϥϦΛ༻ w ԼҐͱଓ͍͢͠Α͏ʹXSBQ͢Δ
ϨΠϠʔͷڥքɺӽڥ
ϨΠϠʔͷڥքɺӽڥ ڥքͷҾ͖͔ͨ • γεςϜΛίϯϙʔωϯτʹׂ͢Δ • ݪଇɺϧʔϧΛݩʹ֤ϨΠϠʔʹྨ͢Δ • ґଘؔͷઢΛҾ͍ͯΈΔ
ϨΠϠʔͷڥքɺӽڥ ӽڥͷ͔ͨ͠ • DIPΛͬͯґଘͷ͖Λίϯτϩʔϧ͢Δ 3FQPTJUPSZ 6TFDBTF 6TFDBTF 3FQPTJUPSZ JOUFSGBDF 3FQPTJUPSZ
*OUFSGBDF"EBQUFS 6TFDBTF %*1ద༻લ %*1ద༻ޙ
ϨΠϠʔͷڥքɺӽڥ ӽڥͷ͔ͨ͠ TSDQLHVTFDBTFVTFSJOUFSBDUPSHP TSDQLHJOUFSGBDFVTFSDPOUSPMMFSHP ܕVTFDBTF6TFS3FQPTJUPSZ ࣮ࡍʹೖΕͯΔͷEBUBCBTF6TFS3FQPTJUPSZ
GoͰCA࠾༻͢ΔͱͲ͏ʁ
GoͰCA࠾༻͢ΔͱͲ͏ʁ ϥΠϒϥϦʹґଘ͗͢͠ͳ͍ • αʔυύʔςΟͷϥΠϒϥϦ͍͗ͣ͢ɺ͋͘ ·Ͱwrapperͱͯ͠͏ఔʹཹΊΔจԽ͕ ͋Δ • infraҎԼͷ֎෦ίϯϙʔωϯτͷӨڹ͕ গͳ͍ →֎෦ίϯϙʔωϯτͷมߋʹͭΑ͍
GoͰCA࠾༻͢ΔͱͲ͏ʁ MockͭΒ͍ • CAΛ࠾༻͢Δͱinterface͍ͬͺ͍ੜ͑Δ • ࣗ࡞interfacegoMockͳͲͰMockੜ HPMBOHNPDL IUUQTHJUIVCDPNHPMBOHNPDL
GoͰCA࠾༻͢ΔͱͲ͏ʁ ඪ४ύοέʔδΛMock͢Δʹɾɾɾʁ • ςετ͍ͨ͠ϥΠϒϥϦͷinterface, ߏମͱ ϝιου͕Ұக͢ΔinterfaceΛखݩͰ࡞Γ goMockͰMockੜ ͩΔ͍
CAͷ·ͱΊ
CA·ͱΊ ”ਤͷԁɺ֓ཁΛࣔͨ͠ͷͰ͋Δɻ͕ͨͬͯ͠ɺ͜ͷ̐ͭ Ҏ֎ʹඞཁͳͷ͋ΔͩΖ͏ɻͨͩ͠ɺґଘੑͷϧʔϧ ৗʹద༻͞ΕΔ” ”νʔϜͷنϝϯόʔͷεΩϧιϦϡʔγϣϯͷෳࡶ ͞ɺͦͯ࣌ؒ͠ͱ༧ࢉͷ੍ͳͲΛߟྀ͠Α͏” 3PCFSU$.BSUJO
CA·ͱΊ • νʔϜͰ߹ҙ͕औΕ͍ͯΕਖ਼ͳΜͰ ͍͍ͱࢥ͍ͬͯΔ • ԿΛୡ͍͔ͨ͠Λݟਾ͑ɺઌਓ͕ͨ͠ ݪཧݪଇνʔϜͷܦݧɺγεςϜͷಛੑɺ υϝΠϯࣝͳͲΛϑϧʹ׆༻ͯ͠ৗʹద ͳߏʹͳΔΑ͏ྗ͢Δ
CA͓͢͢ΊυΩϡϝϯτ w $MFBO"SDIJUFDUVSFɹୡਓʹֶͿιϑτΣΞͷߏͱઃܭ IUUQTXXXBNB[PODPKQEQ#'4#)47SFGEQLJOEMFSFEJSFDU @FODPEJOH65'CULS w ࣮ફΫϦʔϯΞʔΩςΫνϟ IUUQTOSTMJCDPNDMFBOBSDIJUFDUVSF w $MFBO"SDIJUFDUVSFͰ"1*4FSWFSΛߏஙͯ͠ΈΔ
IUUQTRJJUBDPNIJSPUBLBOJUFNTDGBDDBF
GoΛษڧ͢ΔͳΒ͜ΕಡΜͲ͚
GoΛษڧ͢ΔͳΒ͜ΕಡΜͲ͚ • ॳ৺ऀ w "5PVSPG(P IUUQTHPUPVSKQBQQTQPUDPNXFMDPNF w 1SPHBUF IUUQTQSPHDPNMBOHVBHFTHP
GoΛษڧ͢ΔͳΒ͜ΕಡΜͲ͚ • ॳ৺ऀ~தڃऀ w (PݴޠʹΑΔ8FCΞϓϦέʔγϣϯ։ൃ w (PͰଞͷษڧΛ͢Δ (PͳΒΘ͔ΔγεςϜϓϩάϥϛϯά (PݴޠͰͭ͘ΔΠϯλϓϦλ 3FBM8PSME)551
8SJUJOHdJO(Pܥ
GoΛษڧ͢ΔͳΒ͜ΕಡΜͲ͚ • தڃऀ~্ڃऀ w (PݴޠʹΑΔฒߦॲཧ w ϓϩάϥϛϯάݴޠ(P w ΈΜͳͷ(PݴޠʲݱͰ͑Δ࣮ફςΫχοΫʳ w
&⒎FDUJWF(P ӳޠ൛ɿIUUQTHPMBOHPSHEPDF⒎FDUJWF@HPIUNM ຊޠ൛IUUQHPMBOHKQF⒎FDUJWF@HP
GoΛษڧ͢ΔͳΒ͜ΕಡΜͲ͚ GoDocಡΊ
͓ΘΓ