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
クリーンアーキテクチャ をGoでする場合に不要な Interfaceは消しやがれ
Search
garebare
June 17, 2022
Programming
0
130
クリーンアーキテクチャ をGoでする場合に不要な Interfaceは消しやがれ
6月17日に行われたNEWDEBUG!!!!で発表した史料です。
https://caspur.wintu.dev/front/lives/264
garebare
June 17, 2022
Tweet
Share
More Decks by garebare
See All by garebare
ペンギンをおすすめする
garebareda
0
43
hey-techcamp-2022
garebareda
2
63
Rustで作った自作コマンド群の話
garebareda
0
160
自作Git作った話
garebareda
3
730
Rustで自作言語のインタプリタ作って Webで動くようにした話
garebareda
0
820
Vtuberをやりたくなりました
garebareda
1
75
Other Decks in Programming
See All in Programming
HTTPじゃ遅すぎる! SwitchBotを自作ハブで動かして学ぶBLE通信
occhi
0
130
CSC305 Lecture 13
javiergs
PRO
0
340
CSC305 Lecture 14
javiergs
PRO
0
170
MCPサーバー「モディフィウス」で変更容易性の向上をスケールする / modifius
minodriven
3
190
Vueのバリデーション、結局どれを選べばいい? ― 自作バリデーションの限界と、脱却までの道のり ― / Which Vue Validation Library Should We Really Use? The Limits of Self-Made Validation and How I Finally Moved On
neginasu
3
1.8k
SidekiqでAIに商品説明を生成させてみた
akinko_0915
0
110
React Nativeならぬ"Vue Native"が実現するかも?_新世代マルチプラットフォーム開発フレームワークのLynxとLynxのVue.js対応を追ってみよう_Vue Lynx
yut0naga1_fa
2
2k
CSC509 Lecture 09
javiergs
PRO
0
280
オンデバイスAIとXcode
ryodeveloper
0
370
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
320
One Enishi After Another
snoozer05
PRO
0
170
なんでRustの環境構築してないのにRust製のツールが動くの? / Why Do Rust-Based Tools Run Without a Rust Environment?
ssssota
14
47k
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1371
200k
Designing Experiences People Love
moore
142
24k
BBQ
matthewcrist
89
9.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
A Tale of Four Properties
chriscoyier
161
23k
How GitHub (no longer) Works
holman
315
140k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Testing 201, or: Great Expectations
jmmastey
46
7.7k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
10
900
Rails Girls Zürich Keynote
gr2m
95
14k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Transcript
クリーンアーキテクチャを Goでする場合に不要な Interfaceは消しやがれ @garebare521
By たふみ神
ということで考えて行こうと思います
クリーンアーキテクチャとは
Entity UseCase Cotroller UI DB
なんかこういうやつ!
Interfaceで依存を逆転させてるらしい
実装例 type Hoge struct { … } type HogeUsecase struct
{ … } type HogeRepository struct { …. } type Hoge Controller struct { … }
実装例 hogeRepo:=NewHogeRepository() hogeUse :=NewHogeUsecase(hogeRepo) hogeCtrl := NewHogeCtroller(hogeUse)
実装例 hogeCtrl.Post () hogeUse.Post () HogeRepo.Insert()
Interfaceなしだと モックが作れないので テストし難い
Interface書くしかない
クリーンアーキテクチャを Goでする場合に不要な Interfaceは消しやがれ
じゃあどうするか
とりあえず実装量が少なそうな UseCase層を取り除く
Entity UseCase Cotroller UI DB
Entity Cotroller UI DB
単純にインターフェースを削除すると テストが破綻する
テストしやすい形にしたい
じゃあもう実態持たせる必要なくない?
Entity UI DB Controller
Entity UI DB Controller こうしたい
実態を持たせずに Interfaceと同じようなことをしたい
関数を引数に渡せばよくね????
関数を渡すようにするとテストも書きやすい
HogeController func (c *hogeCtrl) Post(c Context, insert func(hoge Hoge) (error))
{ insert() } hogeCtrl.Post(c, hogeRepo.insert)
関数の引数をInterface代わりにして 解決!
ただ必要な関数が増えるたびに 引数も増えます