Upgrade to Pro — share decks privately, control downloads, hide ads and more …

リアーキテクチャによってどうなりたいか/re-architecture

suzuki-hoge
September 14, 2023

 リアーキテクチャによってどうなりたいか/re-architecture

リアーキテクチャによってどうなりたいか

2023/09/14

asken withミライトデザインのDDDのはじめ方 DDD x RDRA x ICONIX
https://asken.connpass.com/event/293085/

suzuki-hoge

September 14, 2023
Tweet

More Decks by suzuki-hoge

Other Decks in Programming

Transcript

  1. ಉ͜͡ͱΛ࣮ݱ͢Δ 2 ͭͷίʔυ ৯ࣄه࿥഑ྻ< औಘ  औಘ  औಘ 

     > GPS৯ࣄه࿥JO৯ࣄه࿥഑ྻ\ JG৯ࣄه࿥৯ࣄJTOVMM\ CSFBL ^ ^ ࠓ೔ͷΞυόΠεεςʔλε อଘ ࠓ೔ͷΞυόΠε ̏৯෼ͷ৯ࣄه࿥औಘ  JG̏৯෼ͷ৯ࣄه࿥શͯೖྗࡁ \ ࠓ೔ͷΞυόΠεදࣔղې  ^ อଘ ࠓ೔ͷΞυόΠε 
  2. εςʔλε ( Int ) status 1 2 3 1 //

    ਃࠐத 2 // ར༻த 3 // ୀձࡁ // ར༻தͷ৔߹ if user.status == 2 { ... }
  3. εςʔλε ( Int ) 1 // ਃࠐத 2 // ར༻த

    3 // ୀձࡁ // ར༻தͷ৔߹ if user.status == 2 && user.date != null { ... } εςʔλε ୀձਃࠐ೔ 1 2 2 2023/09/08 3 2023/09/01
  4. εςʔλε ( Int ) 1 // ਃࠐத 2 // ར༻த

    3 // ୀձࡁ // ར༻தͷ৔߹ if user.status == 2 && user.date != null { ... } εςʔλε ୀձਃࠐ೔ 1 2 2 2023/09/08 3 2023/09/01 ͏ͦ͡ΌΜʂ
  5. εςʔλε ( Enum ) ਃࠐத ར༻த ୀձॲཧத ୀձࡁ // ར༻தͷ৔߹

    if user.status.ར༻த { ... } εςʔλε ୀձਃࠐ೔ 1 2 2 2023/09/08 3 2023/09/01
  6. DPOODSFBUF$POOFDUJPO   σʔλDPOORVFSZ TFMFDU GSPNSFDPSETXIFSF  ̏৯෼ͷ৯ࣄه࿥OFX̏৯෼ͷ৯ࣄه࿥σʔλ  OFX৯ࣄه࿥σʔλ

    σʔλ<>JE σʔλ<>EBUF σʔλ<>DBMPSJF  OFX৯ࣄه࿥σʔλ σʔλ<>JE σʔλ<>EBUF σʔλ<>DBMPSJF  OFX৯ࣄه࿥σʔλ σʔλ<>JE σʔλ<>EBUF σʔλ<>DBMPSJF   ΞυόΠεOFXΞυόΠε DPOORVFSZ TFMFDU GSPNSFDPSETXIFSF <>JE  JG̏৯෼ͷ৯ࣄه࿥શͯೖྗࡁ \ ΞυόΠεදࣔղې  ^ DPOOFYFDVUF VQEBUFBEWJDFTFUTUBUVT XIFSFJE  ΞυόΠεTUBUVT ΞυόΠεJE
  7. DPOODSFBUF$POOFDUJPO   σʔλDPOORVFSZ TFMFDU GSPNSFDPSETXIFSF  ̏৯෼ͷ৯ࣄه࿥OFX̏৯෼ͷ৯ࣄه࿥σʔλ  OFX৯ࣄه࿥σʔλ

    σʔλ<>JE σʔλ<>EBUF σʔλ<>DBMPSJF  OFX৯ࣄه࿥σʔλ σʔλ<>JE σʔλ<>EBUF σʔλ<>DBMPSJF  OFX৯ࣄه࿥σʔλ σʔλ<>JE σʔλ<>EBUF σʔλ<>DBMPSJF   ΞυόΠεOFXΞυόΠε DPOORVFSZ TFMFDU GSPNSFDPSETXIFSF <>JE  JG̏৯෼ͷ৯ࣄه࿥શͯೖྗࡁ \ ΞυόΠεදࣔղې  ^ DPOOFYFDVUF VQEBUFBEWJDFTFUTUBUVT XIFSFJE  ΞυόΠεTUBUVT ΞυόΠεJE ɹυϝΠϯΛ࢖͏ͨΊͷίʔυͳͷʹ ɹυϝΠϯ࢖ͬͯΔͷ͚ͩ͜͜
  8. Application Domain Repository UseCase Interface Class ίʔυ Infrastructure RepositoryImpl ɾORM

    Λ import ͨ͠Γ ɾ؀ڥม਺ͰڍಈΛม͑ͨΓ ɾϏδωεϧʔϧͷྲྀΕΛ஌Δ࣌ʹݟΔ ɾԿΛಡΈॻ͖͢Δ͔͸खଓ͖ͷҰ؀
  9. GVO͋Δखଓ͖\ ே৯৯ࣄ3FQPTJUPSZGJOE̍৯෼   ன৯৯ࣄ3FQPTJUPSZGJOE̍৯෼   ༦৯৯ࣄ3FQPTJUPSZGJOE̍৯෼  

    ̏৯෼ͷ৯ࣄه࿥OFX̏৯෼ͷ৯ࣄه࿥  ே৯  ன৯  ༦৯  ே৯ӫཆૉ ன৯ӫཆૉ ༦৯ӫཆૉ   ^ ͜Ε͸ΦϒδΣΫτ ͜Ε͕ू໿
  10. GVO͋Δखଓ͖\ ே৯৯ࣄ3FQPTJUPSZGJOE̍৯෼   ன৯৯ࣄ3FQPTJUPSZGJOE̍৯෼   ༦৯৯ࣄ3FQPTJUPSZGJOE̍৯෼  

    ̏৯෼ͷ৯ࣄه࿥OFX̏৯෼ͷ৯ࣄه࿥  ே৯  ன৯  ༦৯  ே৯ӫཆૉ ன৯ӫཆૉ ༦৯ӫཆૉ   ^ ू໿Λ૊ΈཱͯΔ࣮૷Λखଓ͖ଆʹॻ͔ͳ͚Ε͹͍͚ͳ͍ ͜Εຖճॻ͘ͷ͠ΜͲ͍ΑͶ ίϯετϥΫλมΘͬͨΒԿϲॴมߋ͢Δ͜ͱʹͳΔ΍Β...
  11. ͦΕҎ֎ Application Domain ίʔυ Infrastructure Repository UseCase RepositoryImpl ू໿ ίʔυ

    ɹ͘Γ͔͑͠ॻ͖ͨ͘ͳ͍͠ɺ ɹͦ΋ͦ΋υϝΠϯϧʔϧͩ͠ɺ ɹnew ͸ͬͪ͜ʹॻ͍ͨΑͶ
  12. ॻ͘ͱ͖ ( ू໿ ) ৯ࣄه࿥ ৯ࣄه࿥ ৯ࣄه࿥ ɾछผ: ே৯ ɾ࣌ؒ:

    08:30 ɾ৯ࣄ: ೲ౾ɺ͝൧ ɾӫཆૉ: λϯύΫ࣭... ࢷ࣭... ɾࣸਅ: ɾछผ: ன৯ ɾ࣌ؒ: 12:34 ɾ৯ࣄ: ਌ࢠကɺຯḩो ɾӫཆૉ: λϯύΫ࣭... ࢷ࣭... ɾࣸਅ: image.jpg ɾछผ: ༦৯ ɾ࣌ؒ: 19:51 ɾ৯ࣄ: ϋϯόʔάɺαϥμ ɾӫཆૉ: λϯύΫ࣭... ࢷ࣭... ɾࣸਅ: image.jpg ಡΉͱ͖ ( ू໿Ͱ͸ͳ͍͜ͱ͕͋Δ ) ̏৯෼ͷ৯ࣄ࣌ؒ ɾே৯ͷ࣌ؒ: 08:30 ɾன৯ͷ࣌ؒ: 12:34 ɾ༦৯ͷ࣌ؒ: 19:51
  13. Α͘Θ͔Βͳ͍ϝιου͕૿͑Δ ৯ࣄه࿥ϦϙδτϦ\ GVOGJOE#Z*E *E ू໿ GVOJOTFSU ू໿  GVOVQEBUF ू໿

     GVOGJOE#Z6TFS*E 6TFS*E ू໿ˡू໿ѻͬͯΔ͔ΒΪϦηʔϑ  GVOFYJTUT *E #PPMˡ͜Ε͸ηʔϑ  GVOHFU৯ࣄ࣌ؒϦετ *E -JTU5JNFˡू໿͸  GVOHFUன৯ *E ৯ࣄˡू໿ͷҰ෦Ͱ͔͠ͳ͍͚Ͳ  GVOVQEBUF৯ࣄ࣌ؒ *E 5JNF ˡू໿࢖Θͳ͍ͷ   ^ ϥΠϑαΠΫϧΛѻ͏ͷ͕ू໿Ͱɺ Repository ͷ੹຿͸ू໿ͷอଘͱ෮ݩͷ ͸͚ͣͩͲ... ͍ͭ͜Β͸...??
  14. ੑೳతʹແବ͕ଟ͍ ̍೔લSFQPTJUPSZGJOE#Z*E   ̎೔લSFQPTJUPSZGJOE#Z*E   ̏೔લSFQPTJUPSZGJOE#Z*E  

    ̏೔ؒͷ৯ࣄ࣌ؒϦετ<̍೔લ࣌ؒ ̎೔લ࣌ؒ ̏೔લ࣌ؒ> ɹू໿͕̏ͭඞཁͩͱ ɹ̏ճͷ DB ΞΫηε͕ඞཁ ɹ৯ࣄ΍ӫཆૉͷ৘ใΛ join ͯ͠ ɹ෮ݩͨ͠ͷʹɺ͔࣌ؒ͠࢖ͬͯͳ͍
  15. ৯ࣄه࿥3FQPTJUPSZ\ GVOGJOE#Z*E *E ू໿ GVOJOTFSU ू໿  GVOVQEBUF ू໿ 

    ^ ৯ࣄه࿥2VFSZ4FSWJDF\ GVOFYJTUT *E #PPM GVOHFU৯ࣄ࣌ؒϦετ *E -JTU5JNF ^ ू໿ʹूத͢Δ ɹू໿Λ࢖Θͳ͍͜ͱ΋͋Δ ɹͨͩ͠ ಡΈ ͚ͩ
  16. ͦΕҎ֎ Application Domain ίʔυ Interface Class Infrastructure ɹೖྗͷܻ਺νΣοΫ ɹϨεϙϯε Json

    ͷ࡞੒ ɹUseCase ͷ࣮ߦ QueryService QueryServiceImpl Repository UseCase RepositoryImpl ू໿ ίʔυ Factory
  17. API 1 ମॏνΣοΫ 1 API 2 ମॏνΣοΫ 2 API 3

    ମॏνΣοΫ 3 API 4 ମॏνΣοΫ 4 ॏෳίʔυͷϝϯς͸Ҋ֎େม ্ݶΛ 210.0 ʹ͍ͨ͠ ͑ͬ
  18. Presentation Application Infrastructure Domain Request Controller Interface Class ɹUseCase ͷ࣮ߦ

    ɹϨεϙϯε Json ͷ࡞੒ ɹೖྗͷܻ਺νΣοΫ QueryService QueryServiceImpl Repository UseCase RepositoryImpl ू໿ ίʔυ Factory
  19. Presentation Application Infrastructure Domain Request Controller Factory DomainService ू໿ Interface

    Class QueryService QueryServiceImpl Repository UseCase RepositoryImpl
  20. Presentation Application Infrastructure Domain QueryService QueryServiceImpl Repository UseCase Request Controller

    RepositoryImpl Factory DomainService ू໿ ಘ఺ܭࢉϧʔϧ͕มΘͬͨ σʔλߏ଄΋ॲཧϑϩʔ΋ มΘΒͳ͍ͳΒରԠ͸͚ͩ͜͜ Ͱେৎ෉ ࣗಈςετʹ DB ΋͍Βͳ͍
  21. Presentation Application Infrastructure Domain QueryService QueryServiceImpl Repository UseCase Request Controller

    RepositoryImpl Factory DomainService ू໿ ςʔϒϧఆٛม͑ͨ Infrastructure ͷࣗಈςετ ͕௨ͤΕ͹େৎ෉ Application ͷ Interface ͕ มߋͳ͠ͳΒଞʹӨڹͳ͠
  22. Presentation Application Infrastructure Domain QueryService QueryServiceImpl Repository UseCase Request Controller

    RepositoryImpl Factory DomainService ू໿ ϑϩʔͳΒ Application Λ֬ೝ UseCase ͷࣗಈςετΛ͚ͨ͠ Ε͹ Infrastructure ͸ϞοΫͰ े෼ ༗ྉձһͷϑϩʔΛม͍͑ͨ
  23. Presentation Application Infrastructure Domain QueryService QueryServiceImpl Repository UseCase Request Controller

    RepositoryImpl Factory DomainService ू໿ ࢀর࣌ʹ਎௕΋ฦͯ͠ ࢀর৘ใ͸ QueryService Λ த৺ʹରԠ͢Ε͹ OK