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
400
Other Decks in Programming
See All in Programming
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
150
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
290
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
780
.NET Conf 2024の振り返り
tomokusaba
0
110
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
1.3k
Ethereum_.pdf
nekomatu
0
480
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
140
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
320
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.5k
Welcome JSConf.jp 2024
yosuke_furukawa
PRO
0
2.1k
「天気予報があなたに届けられるまで」 - NIFTY Tech Talk #22
niftycorp
PRO
0
120
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Statistics for Hackers
jakevdp
796
220k
Rails Girls Zürich Keynote
gr2m
94
13k
Happy Clients
brianwarren
98
6.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
450
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
24k
Fireside Chat
paigeccino
34
3k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Scaling GitHub
holman
458
140k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Done Done
chrislema
181
16k
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.