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

ドメインロジックと 永続化処理を分離する設計改善 を行って得られた知見 / Design improvements that separate domain logic and persistence function

7f68f5f85f4a39df7d8d3c81cbbfb788?s=47 ぷらす
September 20, 2019

ドメインロジックと 永続化処理を分離する設計改善 を行って得られた知見 / Design improvements that separate domain logic and persistence function

Akatsuki Summer Internship 2019の成果発表会のスライドです。

ブログ↓
ドメインロジックと永続化処理を分離する設計改善を行って得られた知見【アカツキ インターン】
https://blog.p1ass.com/posts/aktsk-intern/

7f68f5f85f4a39df7d8d3c81cbbfb788?s=128

ぷらす

September 20, 2019
Tweet

Transcript

  1. υϝΠϯϩδοΫͱ ӬଓԽॲཧΛ෼཭͢Δઃܭվળ ΛߦͬͯಘΒΕͨ஌ݟ "LBUTVLJ4VNNFS*OUFSOTIJQ੒Ռൃද ؛ ௚ً !QBTT

  2. ࿩͍ͨ͜͠ͱ ࠜڌͷ͋Δઃܭ͸ଟ͘ͷϝϦο τΛڗडͰ͖Δ

  3. 8IPBN* • ؛ ௚ً • 5XJUUFS (JU)VC!QBTT • ژ౎େֶ #

    • αʔόʔαΠυ (P • $".1)03 ӡӦϝϯόʔ ࣗݾ঺հ
  4. None
  5. "HFOEB • ࣗݾ঺հ • Ծ૝௨՟؅ཧαʔϏεͷ঺հ • ઃܭվળΛߦ͏ܦҢ • ݱঢ়ͷ՝୊ •

    ઃܭվળ • ઃܭվળͰಘΒΕͨϝϦοτ • ݸਓతͳֶͼ • ͓ΘΓʹ
  6. Ծ૝௨՟؅ཧαʔϏεͷ ঺հ

  7. ֓ཁ • ήʔϜ಺௨՟؅ཧαʔϏε • ՝ۚΞΠςϜͷ؅ཧ • Ϣʔβͷ࢒ߴ؅ཧ • Ϩγʔτݕূ •

    FUD Ծ૝௨՟؅ཧαʔϏεͷ঺հ ήʔϜ։ൃऀͷ޻਺࡟ݮʹد༩
  8. ࢖ΘΕ͍ͯΔٕज़ελοΫ • (P • (PPHMF"QQ&OHJOF ("& • EBUBTUPSF • $JSDMF$*

    Ծ૝௨՟؅ཧαʔϏεͷ঺հ (PQIFSJ[FNF IUUQTHPQIFSJ[FNF
  9. ઃܭվળΛߦ͏ܦҢ

  10. ϥΠϒϥϦΛมߋ͍ͨ͠ ݱࡏ͸EBUBTUPSF΁ͷΞΫηεʹ NKJCTPOHPPOΛ࢖༻ • ("&ެࣜͷϥΠϒϥϦΛ͍͍ײ͡ʹϥοϓ • ࣗಈΩϟογϡ ࢖͍উखͷྑͦ͞͏ͳ NFSDBSJEBUBTUPSFʹҠߦ͍ͨ͠ •

    ಠࣗʹϛυϧ΢ΣΞΛ࣮૷͢Δ͜ͱ͕Ͱ͖Δ • ֦ுੑ͕ߴ͍ ઃܭվળΛߦ͏ܦҢ
  11. ݱঢ়ͷ՝୊

  12. ີ݁߹ͳυϝΠϯ૚ ϩδοΫͱEBUBTUPSF΁ͷӬଓԽॲཧ͕ࠞ͟Γ߹ͬͯෳࡶ ݱঢ়ͷ՝୊ Is the change list more complex than

    it should be? "Too complex" usually means "can't be understood quickly by code readers." (PPHMFT&OHJOFFSJOH1SBDUJDFTEPDVNFOUBUJPOIUUQTHPPHMFHJUIVCJPFOHQSBDUJDFT
  13. 6OJUUFTUT*OUFHSBUJPOUFTUT • ϩδοΫͷςετ͕͍ͨ͠ͷʹΤϛϡϨʔλͷىಈ͕ඞཁ • ΧόϨοδ͸ߴ͍͕໢ཏੑ͕௿͍ • Ξϯνύλʔϯ ݱঢ়ͷ՝୊ Unit Integration

    E2E UFTUBVUPNBUJPOQZSBNJE
  14. ઃܭվળͷํ਑

  15. ີ݁߹ͳॲཧΛ෼཭͢Δ ✔ ͜ΕΒͷ໰୊͸ີ݁߹ͳ࣮૷ʹىҼ ˣ ૄ݁߹ͳ࣮૷ʹͳΔΑ͏ʹઃܭΛมߋ ઃܭվળ

  16. %*1ͱΠϯλʔϑΣʔεͰந৅Խ ઃܭվળ IUUQTTQFBLFSEFDLDPNQMVTDMFBOBSDIJUFDUVSFJONJOVUFT TMJEF

  17. ࣮૷ ઃܭվળ "EEJUJPOT %FMFUJPOT $IBOHFT

  18. ࣮૷ ઃܭվળ

  19. ઃܭվળͰಘΒΕͨ ϝϦοτ

  20. ςελϏϦςΟͷ޲্ ϞοΫΛ࢖͏͜ͱͰςετ͕ॻ͖΍͘͢ ઃܭվળͰಘΒΕͨϝϦοτ { name: "return error when post failed",

    hoge: &types.Hoge{ HogeID: "invalid” }, injector: func(r *mocks.MockHogeRepository) *mocks.MockHogeRepository { r.EXPECT().Post(gomock.Any(), types.Hoge{HogeID: "invalid"}). Return(nil, errors.New("some error")) return r }, want: nil, wantErr: true, } // ... for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() mockRepo := mocks.NewMockHogeRepository(ctrl) mockRepo = tt.injector(mockRepo) // ... } }
  21. ίʔυͷՄಡੑ͕޲্ ӬଓԽॲཧΛએݴతʹݺͿ͚ͩͰྑ͍ͷͰίʔυ͕͖ͬ͢Γ • ԿΛ͢ΔͨΊͷؔ਺ͳͷ͔͕෼͔Γ΍͍͢ ઃܭվળͰಘΒΕͨϝϦοτ

  22. %#ͷҠߦָ͕ʹ ผ%# FY4QBOOFS ΁ͷҠߦ࣌ʹϩδοΫΛߟ͑Δඞཁ͕ͳ͍ ઃܭվળͰಘΒΕͨϝϦοτ

  23. ݸਓతͳֶͼ

  24. ࠜڌͷ͋Δઃܭ͸ଟ͘ͷ ϝϦοτΛڗडͰ͖Δ

  25. ઃܭͷଘࡏҙٛ ΞʔΩςΫνϟ΍ઃܭख๏͸Կ͔Λղܾ͢ΔͨΊʹੜ·Εͨ • ςετ͕ॻ͖ͮΒ͍ • େن໛ʹͳͬͯ։ൃεϐʔυ͕མͪͨ • FUD ࣗ෼ͷϓϩμΫτͱઃܭख๏ͷ໨త͕Ұக͍ͯ͠ͳ͍ͱແҙຯ ݸਓతͳֶͼ

  26. lͳΜͱͳ͘zͰ͸ͳࠜ͘ڌΛ΋ͬͨઃܭΛ ໨తҙࣝΛ΋ͬͯద੾ͳબఆΛ͠Α͏ • ςετ࣌ؒ୹ॖͷͨΊʹ%#ΛϞοΫʹࠩ͠ସ͍͔͑ͨΒந৅Խ͢Δ • େن໛ͳ։ൃ͔ͩΒɺ੹຿Λ෼཭Ͱ͖ΔΑ͏ʹ$MFBO"SDIJUFDUVSFΛ ࠾༻͢Δ • কདྷੑΑΓ΋։ൃεϐʔυ͕େࣄ͔ͩΒ͋·ΓઃܭΛؾʹ͠ͳ͍ •

    FUD ݸਓతͳֶͼ
  27. ͓ΘΓʹ

  28. ͓ΘΓʹ • ήʔϜ಺௨՟؅ཧαʔϏεͷઃܭվળΛߦͬͨ • طଘͷ՝୊఺Λղফͯ͠ࠓޙͷ։ൃ͕͠΍͘͢ͳΔΑ͏ʹͨ͠ • ࣮͸ଞʹ΋৭Μͳ͜ͱΛɺɺɺ • ZBNM ͔Β

    (PͷςετίʔυΛࣗಈੜ੒͢Δ044ͷ৽ػೳ։ൃ • ෼ࢄΩϟογϡͨΊͷϛυϧ΢ΣΞΛ࣮૷ • FUD
  29. 5IBOLZPV "TLNFBOZUIJOH 5XJUUFS΀Β͢ !QBTT (JU)VCQBTT