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
DDD and Spring Boot
Search
zhanpon
December 15, 2018
Programming
0
2k
DDD and Spring Boot
JJUG CCC 2018 Fallでの発表資料です。
zhanpon
December 15, 2018
Tweet
Share
More Decks by zhanpon
See All by zhanpon
Understanding Coroutines
zhanpon
0
54
Dr. Springlove
zhanpon
0
440
Other Decks in Programming
See All in Programming
MCPを使ってイベントソーシングのAIコーディングを効率化する / Streamlining Event Sourcing AI Coding with MCP
tomohisa
0
190
0から始めるモジュラーモノリス-クリーンなモノリスを目指して
sushi0120
0
210
[DevinMeetupTokyo2025] コード書かせないDevinの使い方
takumiyoshikawa
2
230
「次に何を学べばいいか分からない」あなたへ──若手エンジニアのための学習地図
panda_program
3
680
MySQL9でベクトルカラム登場!PHP×AWSでのAI/類似検索はこう変わる
suguruooki
1
260
What's new in AppKit on macOS 26
1024jp
0
180
AI Ramen Fight
yusukebe
0
120
JetBrainsのAI機能の紹介 #jjug
yusuke
0
150
可変性を制する設計: 構造と振る舞いから考える概念モデリングとその実装
a_suenami
8
1.1k
Streamlitで実現できるようになったこと、実現してくれたこと
ayumu_yamaguchi
2
240
プロダクトという一杯を作る - プロダクトチームが味の責任を持つまでの煮込み奮闘記
hiliteeternal
0
300
コーディングエージェント概観(2025/07)
itsuki_t88
0
460
Featured
See All Featured
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
The Pragmatic Product Professional
lauravandoore
35
6.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Designing for humans not robots
tammielis
253
25k
Rebuilding a faster, lazier Slack
samanthasiow
83
9.1k
Visualization
eitanlees
146
16k
Speed Design
sergeychernyshev
32
1k
Transcript
υϝΠϯۦಈઃܭͱ Spring BootΛ׆༻ͨ͠ ΞϓϦέʔγϣϯ։ൃ Copyright © 2018 Yahoo Japan Corporation.
All rights reserved.
ఆ͢ΔϦεφʔ • Spring BootΛ৮ͬͨ͜ͱ͕͋Δ • DDDʹ͍ͭͯฉ͍ͨ͜ͱ͕͋Δ Copyright © 2018 Yahoo
Japan Corporation. All rights reserved.
ࣗݾհ: @zhanpon • 201710݄ɿϠϑʔʹ৽ଔೖࣾ • 20184݄ɿJava, Spring BootΛ͍͡ΊΔ • 20185݄ɿJJUG
CCC 2018 SpringʹॳࢀՃ ձࣾͰͷओͳ׆ಈ • ਪનγεςϜͷ։ൃɾӡ༻ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
DDDͱԿ͔ • υϝΠϯۦಈઃܭ (Domain-Driven Design) ͷུশ • Eric Evans ͷ
"Domain-Driven Design: Tackling Complexity in the Heart of Software" ͱ͍͏ຊ͕ݩʹͳ͍ͬͯΔ • ෯͍͕͋ͬͯҰݴͰઆ໌Ͱ͖ͳ͍ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
ʢࢲʹͱͬͯʣDDDͱԿ͔ • ΦϒδΣΫτࢦϓϩάϥϛϯάΛݱ࣮ͷෳࡶͳγεςϜʹద ༻͢ΔͨΊͷํ๏ • SOLIDͳઃܭΛ࣮ݱ͢ΔͨΊͷσβΠϯύλʔϯʢ୯Ұͷݪ ଇɺ։์/ดͷݪଇ……ʣ Copyright © 2018
Yahoo Japan Corporation. All rights reserved.
ΞτϥΠϯ 1. DDDΛΔϞνϕʔγϣϯ 2. DDDΛ࣮ફͨ͠ܦݧ 3. ٕज़తͳTIPS Copyright © 2018
Yahoo Japan Corporation. All rights reserved.
Part I: DDDΛΔϞν ϕʔγϣϯ Copyright © 2018 Yahoo Japan Corporation.
All rights reserved.
ࣦഊஊ • ۀΞϓϦέʔγϣϯΛSpring BootͷνϡʔτϦΞϧͷԆͰ ࣮ͨ͠ΒͻͲ͍͜ͱʹͳͬͨ Copyright © 2018 Yahoo Japan
Corporation. All rights reserved.
Α͋͘ΔSpring Bootͷ νϡʔτϦΞϧ 1. ΤϯςΟςΟΛ࣮͢Δ 2. ϦϙδτϦΛఆٛ͢Δ 3. ίϯτϩʔϥʔΛ࣮͢Δ 4.
ʂ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
ΤϯςΟςΟΛ࣮͢Δ @Entity public class User { @Id private String id;
private String fullName; // getterͱsetter } Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
ϦϙδτϦΛఆٛ͢Δ public interface UserRepository extends CrudRepository<User, String> { } Copyright
© 2018 Yahoo Japan Corporation. All rights reserved.
ίϯτϩʔϥʔΛ࣮͢Δ @RestController public class UserController { @Autowired UserRepository userRepository; @GetMapping("/users")
public List<User> allUsers() { return userRepository.findAll(); } } Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
ʂ • ͋ͱ UserController ʹϩδοΫΛॻ͍͍͚ͯOK (?) Copyright © 2018 Yahoo
Japan Corporation. All rights reserved.
• UserΫϥεͷΧϓηϧԽʁ • UserController ͕ࡍݶͳ͘ෳࡶԽ͢Δ • ୯ମςετ͕ࠔ Copyright ©
2018 Yahoo Japan Corporation. All rights reserved.
υϝΠϯϞσϧශ݂ • ୯ͳΔखଓ͖ܕઃܭʹͳͬͯΔ Copyright © 2018 Yahoo Japan Corporation. All
rights reserved.
Part II: DDDΛ࣮ફͨ͠ ࣮ྫ Copyright © 2018 Yahoo Japan Corporation.
All rights reserved.
ࣾͷϓϩδΣΫτ • ػցֶशͷՌΛຖࣗಈͰσϓϩΠ͍ͨ͠ Copyright © 2018 Yahoo Japan Corporation. All
rights reserved.
φΠʔϒʹ࣮ͨ͠Β • ϦϙδτϦʹΞΫηε͢ΔΫϥε (DockerRegistryAccessor) ͱ࣮ߦڥʹσϓϩΠ͢ΔΫϥε (KubernetesDeployer) Λ༻ ҙ͢Δ • DockerRegistryAccessor
͕࠷৽൛Λऔͬͯ͘Δ • KubernetesDeployer ͕ͦΕΛσϓϩΠ͢Δ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
φΠʔϒʹ࣮ͨ͠Β • ͱΓ࣮͋͑ͣͰ͖ͦ͏ɻ͔ͬ͠͠ͱෳࡶʹͳͬͨΒʁ • UserControllerͷΑ͏ʹͲΜͲΜෳࡶʹͳΔ Copyright © 2018 Yahoo Japan
Corporation. All rights reserved.
૿͑Δཁ݅ • ࣗಈσϓϩΠ͢Δ࣌ؒଳΛ੍ݶ͍ͨ͠ • ٳσϓϩΠΛېࢭ͍ͨ͠ • ࠷৽൛͡Όͳͯ҆͘ఆ൛ΛσϓϩΠ͍ͨ͠ Copyright © 2018
Yahoo Japan Corporation. All rights reserved.
υϝΠϯϞσϧΛݟग़͢ • ιϑτΣΞγεςϜͷ͏ͪɺ͕ࣗݩʑղ͖͔ͨͬͨΛ දݱ͢ΔίʔυͷΊΔྔগͳ͍ • ͦͷ෦͕WebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͳͲͷٕज़త ৄࡉʹຒΕͳ͍Α͏ʹ͍ͨ͠ • υϝΠϯ͕ٕज़తৄࡉʹґଘ͠ͳ͍Α͏ʹ͢Δ (DIP)
Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
ࠓճͷυϝΠϯϞσϧ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
Version • ఆظతʹੜ͞ΕΔػցֶशͷՌɻྫɿݘೣྨثͷ2018 12݄159࣌όʔδϣϯ @Value public class Version { private
final String modelName; private final Instant instant; } Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
VersionSet • Set<Version>ͷϥούʔ Copyright © 2018 Yahoo Japan Corporation. All
rights reserved.
Policy public enum Policy { NONE((versions, t) -> Optional.empty()), LATEST((versions,
t) -> { return versions.latest(); }) private BiFunction<VersionSet, Instant, Optional<Version>> policy; Policy(BiFunction<VersionSet, Instant, Optional<Version>> policy) { this.policy = policy; } } Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
VersionCatalog public interface VersionCatalog { VersionSet list(String modelName); } Copyright
© 2018 Yahoo Japan Corporation. All rights reserved.
Deployer public interface Deployer { void deploy(Version version); } Copyright
© 2018 Yahoo Japan Corporation. All rights reserved.
༷มߋ • ػցֶशͷՌΛஷΊΔॴ͕Docker Registry͔ΒΦϒδΣ ΫτετϨʔδʹͳͬͨ ! • VersionCatalog ͷ࣮ΫϥεΛม͑Δ͚ͩ Copyright
© 2018 Yahoo Japan Corporation. All rights reserved.
DDDΛͬͯྑ͔ͬͨ͜ͱ • ༷มߋָ͕ • ςετ͕͍͢͠ • ࣗͷʹର͢Δཧղ͕ίʔυͱͯ͠දݱ͞ΕΔ Copyright © 2018
Yahoo Japan Corporation. All rights reserved.
࠷ޙʹ ͯ͢ͷιϑτΣΞγεςϜɺεςʔΫϗϧμʔʹ2ͭͷҟͳ ΔՁΛఏڙ͢ΔɻͦΕʮৼΔ͍ʯͱʮߏʯͰ͋Δɻ — Robert C. Martin Copyright © 2018
Yahoo Japan Corporation. All rights reserved.
͓·͚ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
Part III: ٕज़తͳTIPS Copyright © 2018 Yahoo Japan Corporation. All
rights reserved.
ϓϩδΣΫτߏ • domainͱapplicationͱ͍͏2ͭͷGradleϓϩδΣΫτΛ࡞ͬͨ • domainJavaͷඪ४ϥΠϒϥϦʹ͔͠ґଘ͍ͯ͠ͳ͍ • applicationdomainʹґଘ͍ͯ͠Δɻத;ͭ͏ͷSpring Boot ΞϓϦέʔγϣϯ Copyright
© 2018 Yahoo Japan Corporation. All rights reserved.