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
Go の GC の不得意な部分を克服したい
taiyow
2
770
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
710
Refactor your code - refactor yourself
xosofox
1
260
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
testcontainers のススメ
sgash708
1
120
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
Security_for_introducing_eBPF
kentatada
0
110
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
快速入門可觀測性
blueswen
0
340
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
For a Future-Friendly Web
brad_frost
175
9.4k
A Tale of Four Properties
chriscoyier
157
23k
Building Your Own Lightsaber
phodgson
103
6.1k
Building Adaptive Systems
keathley
38
2.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Documentation Writing (for coders)
carmenintech
66
4.5k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Music & Morning Musume
bryan
46
6.2k
Fireside Chat
paigeccino
34
3.1k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
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ಡΊ
͓ΘΓ