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
90
クリーンアーキテクチャ を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
15
hey-techcamp-2022
garebareda
2
47
Rustで作った自作コマンド群の話
garebareda
0
120
自作Git作った話
garebareda
3
560
Rustで自作言語のインタプリタ作って Webで動くようにした話
garebareda
0
630
Vtuberをやりたくなりました
garebareda
1
60
Other Decks in Programming
See All in Programming
Revisiting the Hotwire Landscape after Turbo 8 @ RailsConf 2024, Detroit
marcoroth
0
340
『Railsオワコン』と言われる時代に、なぜブルーモ証券はRailsを選ぶのか
free_world21
2
400
Git Rebase
bkuhlmann
11
1.6k
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
2
210
CDKコントリビュートの最初の壁を越えよう! -簡単issueの見つけ方-
badmintoncryer
3
360
Kotlin Multiplatform at Stable and Beyond (Android Makers 2024)
zsmb
0
550
Komplexe Oberflächen mit SVG und der Web Animation API
joergneumann
0
690
The Cutting Edge Of Versioning (LambdaConf 2024)
chriskrycho
0
230
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
290
Introducing Kotlin Multiplatform in an existing mobile app - Workshop Edition | AndroidMakers Paris
prof18
0
170
MicrosoftのPlatform Engineeringガイドを読んで実際になにかやってみた
ymd65536
1
530
Elm Form Validation
bkuhlmann
0
520
Featured
See All Featured
The Mythical Team-Month
searls
217
42k
Clear Off the Table
cherdarchuk
85
310k
Documentation Writing (for coders)
carmenintech
60
4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
242
1.2M
Into the Great Unknown - MozCon
thekraken
15
1k
Debugging Ruby Performance
tmm1
70
11k
KATA
mclloyd
16
12k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
9
1.3k
Building an army of robots
kneath
300
41k
Designing for Performance
lara
601
67k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
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代わりにして 解決!
ただ必要な関数が増えるたびに 引数も増えます