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
420
Other Decks in Programming
See All in Programming
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
110
Develop Faster With FrankenPHP
dunglas
2
3.1k
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
150
地域ITコミュニティの活性化とAWSに移行してみた話
yuukis
0
200
The Weight of Data: Rethinking Cloud-Native Systems for the Age of AI
hollycummins
0
240
PHPUnit 高速化テクニック / PHPUnit Speedup Techniques
pinkumohikan
1
1.3k
AIコードエディタの基盤となるLLMのFlutter性能評価
alquist4121
0
190
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
2.3k
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
680
Agentic Applications with Symfony
el_stoffel
2
200
私の愛したLaravel 〜レールを超えたその先へ〜
kentaroutakeda
12
3.7k
RubyKaigiで手に入れた HHKB Studioのための HIDRawドライバ
iberianpig
0
1.1k
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
30k
Rebuilding a faster, lazier Slack
samanthasiow
80
8.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
118
51k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
A better future with KSS
kneath
239
17k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
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.