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
160
learning-cleanarchitecture-in-go
Takashi Matsuyuki
February 28, 2019
Tweet
Share
More Decks by Takashi Matsuyuki
See All by Takashi Matsuyuki
新規事業立ち上げ、グロースで きちんと”デリバリー”も"ディスカバリー"も し続けられるアジャイル組織の作り方
applepine1125
2
1.6k
最後に勝つ負け方を知っておく
applepine1125
1
410
評価者を孤独にしない
applepine1125
15
5.7k
"OKR"と"野望"で、 メンバーと組織をアラインメントする
applepine1125
5
950
君たちはどうユーザーと向き合うか
applepine1125
0
380
Self-Organizing Product Development Team: Empowered Output Cycle and Collaborative Culture
applepine1125
0
910
オーナーシップを持ち自己組織化するチームに必要な 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
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
810
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.3k
Haze - Real time background blurring
chrisbanes
1
510
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
선언형 UI에서의 상태관리
l2hyunwoo
0
170
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
470
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
快速入門可觀測性
blueswen
0
370
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
280
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
380
Featured
See All Featured
Designing for humans not robots
tammielis
250
25k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Faster Mobile Websites
deanohume
305
30k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Gamification - CAS2011
davidbonilla
80
5.1k
Bash Introduction
62gerente
608
210k
Building Applications with DynamoDB
mza
91
6.1k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Visualization
eitanlees
146
15k
Side Projects
sachag
452
42k
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ಡΊ
͓ΘΓ