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
初めてDefinitelyTypedにPRを出した話
syumai
0
400
Realtime API 入門
riofujimon
0
150
Contemporary Test Cases
maaretp
0
140
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
CSC509 Lecture 12
javiergs
PRO
0
160
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
170
subpath importsで始めるモック生活
10tera
0
300
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
Featured
See All Featured
Faster Mobile Websites
deanohume
305
30k
BBQ
matthewcrist
85
9.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Why Our Code Smells
bkeepers
PRO
334
57k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
How to Ace a Technical Interview
jacobian
276
23k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Making Projects Easy
brettharned
115
5.9k
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ಡΊ
͓ΘΓ