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
150
0
Share
クリーンアーキテクチャ をGoでする場合に不要な Interfaceは消しやがれ
6月17日に行われたNEWDEBUG!!!!で発表した史料です。
https://caspur.wintu.dev/front/lives/264
garebare
June 17, 2022
More Decks by garebare
See All by garebare
ペンギンをおすすめする
garebareda
0
54
hey-techcamp-2022
garebareda
2
77
Rustで作った自作コマンド群の話
garebareda
0
180
自作Git作った話
garebareda
3
780
Rustで自作言語のインタプリタ作って Webで動くようにした話
garebareda
0
870
Vtuberをやりたくなりました
garebareda
1
83
Other Decks in Programming
See All in Programming
「なんか〇〇ライブラリで脆弱性あるみたいなんだけど。。。」から始める脆弱性対応 / First Steps in Vulnerability Response
mackey0225
2
120
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
My daily life on Ruby
a_matsuda
3
380
【ディップ|26年新卒研修資料】OpenAPI/Swagger REST API研修
dip_tech
PRO
0
160
【ディップ|26年新卒研修資料】TDD実装演習
dip_tech
PRO
0
190
AI-DLC Deep Dive
yuukiyo
9
5.9k
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
490
空間オーディオの活用
objectiveaudio
0
150
UaaL×Androidアプリのメモリ計測 — Memory Profilerの先へ
rio432
0
160
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
150
Import assertionsが消えた日~ECMAScriptの仕様はどう決まり、なぜ覆るのか~
bicstone
2
180
継続的な負荷検証を目指して
pyama86
3
1.2k
Featured
See All Featured
Designing Experiences People Love
moore
143
24k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.2k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.7k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
The Language of Interfaces
destraynor
162
26k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
300
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
170
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
A Soul's Torment
seathinner
6
2.8k
Darren the Foodie - Storyboard
khoart
PRO
3
3.3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
360
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代わりにして 解決!
ただ必要な関数が増えるたびに 引数も増えます