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
1.9k
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
46
Dr. Springlove
zhanpon
0
410
Other Decks in Programming
See All in Programming
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
560
Kaigi on Railsに初参加したら、その日にLT登壇が決定した件について
tama50505
0
120
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.1k
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
190
Jaspr Dart Web Framework 박제창 @Devfest 2024
itsmedreamwalker
0
120
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
170
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
150
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
180
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
120
Оптимизируем производительность блока Казначейство
lamodatech
0
770
テストコード書いてみませんか?
onopon
2
240
為你自己學 Python
eddie
0
390
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Building Your Own Lightsaber
phodgson
103
6.1k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Six Lessons from altMBA
skipperchong
27
3.5k
Making Projects Easy
brettharned
116
6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
Done Done
chrislema
182
16k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
How GitHub (no longer) Works
holman
311
140k
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.