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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
garebare
June 17, 2022
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
クリーンアーキテクチャ を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
60
hey-techcamp-2022
garebareda
2
80
Rustで作った自作コマンド群の話
garebareda
0
180
自作Git作った話
garebareda
3
810
Rustで自作言語のインタプリタ作って Webで動くようにした話
garebareda
0
870
Vtuberをやりたくなりました
garebareda
1
91
Other Decks in Programming
See All in Programming
MySQLとPostgreSQLって何が違うの?
akagami
PRO
0
170
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
290
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
Press start. Python's next generation.
willingc
PRO
3
310
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
260
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
470
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
4
2.8k
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
130
Go を使い始めて 2 ヶ月の学び / My first two months with Go
contour_gara
0
420
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
0
370
業務時間外もAIに働いてもらう話
colorful12
3
10k
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
54
36k
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Unsuck your backbone
ammeep
672
58k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
200
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.2k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
410
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
580
Documentation Writing (for coders)
carmenintech
77
5.5k
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代わりにして 解決!
ただ必要な関数が増えるたびに 引数も増えます