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.7k
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
44
Dr. Springlove
zhanpon
0
330
Other Decks in Programming
See All in Programming
SIMD Parallel Programming with the Vector API
josepaumard
0
160
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
270
"config" ってなんだ? / What is "config"?
okashoi
0
240
[技育CAMPアカデミア]アイディアを形に!【超入門】スマホアプリ開発〜リリースまでの流れをご紹介
teamlab
PRO
0
370
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
760
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
760
Fragment Composition of GraphQL
quramy
6
880
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
1
160
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
260
HUIT新歓2024「競技プログラミング、やってみませんか?」
slephy2784
1
270
Goのmultiple errorsについて (2024年4月版)
syumai
3
690
エンターテイメント業界で利用されるAWS
demuyan
0
210
Featured
See All Featured
WebSockets: Embracing the real-time Web
robhawkes
59
7k
Six Lessons from altMBA
skipperchong
21
3k
What's in a price? How to price your products and services
michaelherold
237
11k
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.6k
Facilitating Awesome Meetings
lara
42
5.6k
Faster Mobile Websites
deanohume
299
30k
Robots, Beer and Maslow
schacon
PRO
155
7.9k
Clear Off the Table
cherdarchuk
84
310k
How To Stay Up To Date on Web Technology
chriscoyier
782
250k
Designing for Performance
lara
601
67k
Making Projects Easy
brettharned
108
5.5k
Building Your Own Lightsaber
phodgson
99
5.7k
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.