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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
790
Rustで自作言語のインタプリタ作って Webで動くようにした話
garebareda
0
870
Vtuberをやりたくなりました
garebareda
1
83
Other Decks in Programming
See All in Programming
[KCD Czech] eBPF Meets the GPU: Future of AI Infra Observability
doniacld
0
130
Swiftのレキシカルスコープ管理
kntkymt
0
210
Oxlintのカスタムルールの現況
syumai
5
920
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
260
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
OCRを使ってゲームのアイテムをデータ化する
kishikawakatsumi
0
120
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
180
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
7
2.6k
プラグインで拡張される Context をtype-safe にする難しさと設計判断
kazupon
2
500
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
2.5k
net-httpのHTTP/2対応について
naruse
0
390
AI時代のUIはどこへ行く?その2!
yusukebe
16
5.2k
Featured
See All Featured
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.8k
Bash Introduction
62gerente
615
210k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Chasing Engaging Ingredients in Design
codingconduct
0
200
Information Architects: The Missing Link in Design Systems
soysaucechin
0
950
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
300
Six Lessons from altMBA
skipperchong
29
4.3k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
370
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
260
Un-Boring Meetings
codingconduct
0
300
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
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代わりにして 解決!
ただ必要な関数が増えるたびに 引数も増えます