Save 37% off PRO during our Black Friday Sale! »

DDD and Spring Boot

09387cf644abcfd34e981378f9e70541?s=47 zhanpon
December 15, 2018

DDD and Spring Boot

JJUG CCC 2018 Fallでの発表資料です。

09387cf644abcfd34e981378f9e70541?s=128

zhanpon

December 15, 2018
Tweet

Transcript

  1. υϝΠϯۦಈઃܭͱ Spring BootΛ׆༻ͨ͠ ΞϓϦέʔγϣϯ։ൃ Copyright © 2018 Yahoo Japan Corporation.

    All rights reserved.
  2. ૝ఆ͢ΔϦεφʔ • Spring BootΛ৮ͬͨ͜ͱ͕͋Δ • DDDʹ͍ͭͯฉ͍ͨ͜ͱ͕͋Δ Copyright © 2018 Yahoo

    Japan Corporation. All rights reserved.
  3. ࣗݾ঺հ: @zhanpon • 2017೥10݄ɿϠϑʔʹ৽ଔೖࣾ • 2018೥4݄ɿJava, Spring BootΛ࢖͍͸͡ΊΔ • 2018೥5݄ɿJJUG

    CCC 2018 SpringʹॳࢀՃ ձࣾͰͷओͳ׆ಈ • ਪનγεςϜͷ։ൃɾӡ༻ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  4. DDDͱ͸Կ͔ • υϝΠϯۦಈઃܭ (Domain-Driven Design) ͷུশ • Eric Evans ͷ

    "Domain-Driven Design: Tackling Complexity in the Heart of Software" ͱ͍͏ຊ͕ݩʹͳ͍ͬͯΔ • ෯޿͍࿩୊͕͋ͬͯҰݴͰ͸આ໌Ͱ͖ͳ͍ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  5. ʢࢲʹͱͬͯʣDDDͱ͸Կ͔ • ΦϒδΣΫτࢦ޲ϓϩάϥϛϯάΛݱ࣮ͷෳࡶͳγεςϜʹద ༻͢ΔͨΊͷํ๏࿦ • SOLIDͳઃܭΛ࣮ݱ͢ΔͨΊͷσβΠϯύλʔϯʢ୯Ұ੹೚ͷݪ ଇɺ։์/ด࠯ͷݪଇ……ʣ Copyright © 2018

    Yahoo Japan Corporation. All rights reserved.
  6. Ξ΢τϥΠϯ 1. DDDΛ΍ΔϞνϕʔγϣϯ 2. DDDΛ࣮ફͨ͠ܦݧ 3. ٕज़తͳTIPS Copyright © 2018

    Yahoo Japan Corporation. All rights reserved.
  7. Part I: DDDΛ΍ΔϞν ϕʔγϣϯ Copyright © 2018 Yahoo Japan Corporation.

    All rights reserved.
  8. ࣦഊஊ • ۀ຿ΞϓϦέʔγϣϯΛSpring BootͷνϡʔτϦΞϧͷԆ௕Ͱ ࣮૷ͨ͠ΒͻͲ͍͜ͱʹͳͬͨ Copyright © 2018 Yahoo Japan

    Corporation. All rights reserved.
  9. Α͋͘ΔSpring Bootͷ νϡʔτϦΞϧ 1. ΤϯςΟςΟΛ࣮૷͢Δ 2. ϦϙδτϦΛఆٛ͢Δ 3. ίϯτϩʔϥʔΛ࣮૷͢Δ 4.

    ׬੒ʂ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  10. ΤϯςΟςΟΛ࣮૷͢Δ @Entity public class User { @Id private String id;

    private String fullName; // getterͱsetter } Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  11. ϦϙδτϦΛఆٛ͢Δ public interface UserRepository extends CrudRepository<User, String> { } Copyright

    © 2018 Yahoo Japan Corporation. All rights reserved.
  12. ίϯτϩʔϥʔΛ࣮૷͢Δ @RestController public class UserController { @Autowired UserRepository userRepository; @GetMapping("/users")

    public List<User> allUsers() { return userRepository.findAll(); } } Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  13. ׬੒ʂ • ͋ͱ͸ UserController ʹϩδοΫΛॻ͍͍͚ͯ͹OK (?) Copyright © 2018 Yahoo

    Japan Corporation. All rights reserved.
  14. ໰୊఺ • UserΫϥεͷΧϓηϧԽ͸ʁ • UserController ͕ࡍݶͳ͘ෳࡶԽ͢Δ • ୯ମςετ͕ࠔ೉ Copyright ©

    2018 Yahoo Japan Corporation. All rights reserved.
  15. υϝΠϯϞσϧශ݂঱ • ୯ͳΔखଓ͖ܕઃܭʹͳͬͯΔ Copyright © 2018 Yahoo Japan Corporation. All

    rights reserved.
  16. Part II: DDDΛ࣮ફͨ͠ ࣮ྫ Copyright © 2018 Yahoo Japan Corporation.

    All rights reserved.
  17. ࣾ಺ͷϓϩδΣΫτ • ػցֶशͷ੒Ռ෺Λຖ೔ࣗಈͰσϓϩΠ͍ͨ͠ Copyright © 2018 Yahoo Japan Corporation. All

    rights reserved.
  18. φΠʔϒʹ࣮૷ͨ͠Β • ϦϙδτϦʹΞΫηε͢ΔΫϥε (DockerRegistryAccessor) ͱ࣮ߦ؀ڥʹσϓϩΠ͢ΔΫϥε (KubernetesDeployer) Λ༻ ҙ͢Δ • DockerRegistryAccessor

    ͕࠷৽൛Λऔͬͯ͘Δ • KubernetesDeployer ͕ͦΕΛσϓϩΠ͢Δ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  19. φΠʔϒʹ࣮૷ͨ͠Β • ͱΓ࣮͋͑ͣ૷Ͱ͖ͦ͏ɻ͔͠͠΋ͬͱෳࡶʹͳͬͨΒʁ • UserControllerͷΑ͏ʹͲΜͲΜෳࡶʹͳΔ Copyright © 2018 Yahoo Japan

    Corporation. All rights reserved.
  20. ૿͑Δཁ݅ • ࣗಈσϓϩΠ͢Δ࣌ؒଳΛ੍ݶ͍ͨ͠ • ٳ೔͸σϓϩΠΛېࢭ͍ͨ͠ • ࠷৽൛͡Όͳͯ҆͘ఆ൛ΛσϓϩΠ͍ͨ͠ Copyright © 2018

    Yahoo Japan Corporation. All rights reserved.
  21. υϝΠϯϞσϧΛݟग़͢ • ιϑτ΢ΣΞγεςϜͷ͏ͪɺࣗ෼͕ݩʑղ͖͔ͨͬͨ໰୊Λ දݱ͢Δίʔυͷ઎ΊΔྔ͸গͳ͍ • ͦͷ෦෼͕WebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͳͲͷٕज़త ৄࡉʹຒ΋Εͳ͍Α͏ʹ͍ͨ͠ • υϝΠϯ૚͕ٕज़తৄࡉʹґଘ͠ͳ͍Α͏ʹ͢Δ (DIP)

    Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  22. ࠓճͷυϝΠϯϞσϧ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.

  23. Version • ఆظతʹੜ੒͞ΕΔػցֶशͷ੒Ռ෺ɻྫɿݘೣ෼ྨثͷ2018 ೥12݄15೔9࣌όʔδϣϯ @Value public class Version { private

    final String modelName; private final Instant instant; } Copyright © 2018 Yahoo Japan Corporation. All rights reserved.
  24. VersionSet • Set<Version>ͷϥούʔ Copyright © 2018 Yahoo Japan Corporation. All

    rights reserved.
  25. 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.
  26. VersionCatalog public interface VersionCatalog { VersionSet list(String modelName); } Copyright

    © 2018 Yahoo Japan Corporation. All rights reserved.
  27. Deployer public interface Deployer { void deploy(Version version); } Copyright

    © 2018 Yahoo Japan Corporation. All rights reserved.
  28. ࢓༷มߋ • ػցֶशͷ੒Ռ෺ΛஷΊΔ৔ॴ͕Docker Registry͔ΒΦϒδΣ ΫτετϨʔδʹͳͬͨ ! • VersionCatalog ͷ࣮૷ΫϥεΛม͑Δ͚ͩ Copyright

    © 2018 Yahoo Japan Corporation. All rights reserved.
  29. DDDΛ΍ͬͯྑ͔ͬͨ͜ͱ • ࢓༷มߋָ͕ • ςετ͕͠΍͍͢ • ࣗ෼ͷ໰୊ʹର͢Δཧղ͕ίʔυͱͯ͠දݱ͞ΕΔ Copyright © 2018

    Yahoo Japan Corporation. All rights reserved.
  30. ࠷ޙʹ ͢΂ͯͷιϑτ΢ΣΞγεςϜ͸ɺεςʔΫϗϧμʔʹ2ͭͷҟͳ ΔՁ஋Λఏڙ͢ΔɻͦΕ͸ʮৼΔ෣͍ʯͱʮߏ଄ʯͰ͋Δɻ — Robert C. Martin Copyright © 2018

    Yahoo Japan Corporation. All rights reserved.
  31. ͓·͚ Copyright © 2018 Yahoo Japan Corporation. All rights reserved.

  32. Part III: ٕज़తͳTIPS Copyright © 2018 Yahoo Japan Corporation. All

    rights reserved.
  33. ϓϩδΣΫτߏ੒ • domainͱapplicationͱ͍͏2ͭͷGradleϓϩδΣΫτΛ࡞ͬͨ • domain͸Javaͷඪ४ϥΠϒϥϦʹ͔͠ґଘ͍ͯ͠ͳ͍ • application͸domainʹґଘ͍ͯ͠Δɻத਎͸;ͭ͏ͷSpring Boot ΞϓϦέʔγϣϯ Copyright

    © 2018 Yahoo Japan Corporation. All rights reserved.