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

SPAのAPI開発の「やりづらさ」をDDDとオブジェクト指向の発想で解決する

 SPAのAPI開発の「やりづらさ」をDDDとオブジェクト指向の発想で解決する

PHPカンファレンス2020 前夜祭にて発表

B793da271a45d149b52f507bca9f137c?s=128

Hiromi Hishida

December 11, 2020
Tweet

Transcript

  1. CZ!XFCUI%FD BU1)1$POGFSFODF 41"ͷ"1*։ൃͷ΍ΓͮΒ͞Λ%%% ͱΦϒδΣΫτࢦ޲ͷൃ૝Ͱղܾ͢Δ

  2. w ϑϦʔϥϯεˠΧϧςοτίϛϡχ έʔγϣϯζ։ൃ෦ɺݱࡏόοΫΤ ϯυϦʔυΤϯδχΞ w ೔ຊ4ZNGPOZϢʔβʔձʢ։ళٳ ۀঢ়ଶʜʣ w ʮਓʹ࢖ΘΕΔγεςϜʯΛ࡞Γͨ ͯ͘ɺϝϯςφϏϦςΟͷߴ͍։ൃ

    Λ໨ࢦͯ͠νʔϜϝϯόʔͱҰॹʹ ೔ʑฃಆதʂ w NPUIFSPG
  3. ର৅ w 41"ͷ"1* w TFSWFSUPTFSWFSͷ"1*͸ݪଇͱͯ͠είʔϓ֎Ͱ͕͢ɺࢀߟʹͰ͖Δ෦෼ ͸͋Δ͔΋͠Ε·ͤΜ

  4. ݹ͖ྑ͖ϑϩϯτΤϯυ։ൃ  QIQ PO$MJDLlʜz ʢಉ͡ਓ͕΍Δʣ

  5. ݱ୅ͷϑϩϯτΤϯυ։ൃ <?php @Component({}) export class MyComponent extends OnInit {...} ʢҧ͏ਓ͕΍Δʣ

  6. ݹ͖ྑ͖"1*։ൃ w TFSWFSUPTFSWFSࣗࣾͷσʔλΛଞࣾʢύʔτφʔʣʹެ։͢Δ w "NB[POΞιγΤΠτ8FCαʔϏεʢݱࡏͷ1SPEVDU"EWFSUJTJOH"1*ʣ w (PPHMF.BQT"1* w (PPHMF޿ࠂ"1* :BIPP޿ࠂ"1*ͳͲ

    w ʮݹ͖ྑ͖ʯͱॻ͖·͕ͨ͠ݱࡏͰ΋΋ͪΖΜੜ͖͍ͯ·͢
  7. ݱ୅ͷ"1*։ൃ w TFSWFSUPCSPXTFSPSTFSWFSUPNPCJMFBQQࣗࣾͷσʔλΛࣗࣾͷ41"ʢϑ ϩϯτΤϯυʣʹҾ͖౉͢ w ݹ͖ྑ͖"1*։ൃʹ͸ͳ͍ಛघੑ͕͋Δ

  8. 41"ͷ"1*։ൃͷಛघੑ w "1*Λ࡞ΔਓͱϑϩϯτΤϯυΛ࡞Δਓʢʹ"1*Λ࢖͏ਓʣ͕ಉ͡૊৫ʹଐ͠ ͓ͯΓɺ྆ऀͷ࢓ࣄΛ౷߹ͯͭ͠ͷγεςϜΛ࡞Ζ͏ͱ͍ͯ͠Δ͜ͱ w ͱ͸͍͑ɺݱ୅Ͱ͸௒େاۀ΍੓෎ɾ࣏ࣗମʢΦʔϓϯσʔλʣҎ֎ͷେ൒ ͷ։ൃऀͷߦ͏"1*։ൃ͸41"ͷ"1*։ൃͳͷͰɺ΋͸΍ಛघੑͰ͸ͳͦ͘ Ε͕ී௨ʁ

  9. 41"ͷ"1*։ൃͷ΍ΓͮΒ͞ w ϩδοΫͷॏෳ w τϥϯβΫγϣϯͰ͖ͳ͍ w ͜ͷ"1*ɺଞʹͲ͜Ͱ࢖ΘΕ͍͚ͯͨͬʁʂ໰୊ w O 

  10. ϩδοΫͷॏෳ w όοΫΤϯυͱϑϩϯτΤϯυͷ྆ํʹಉ͡ϩδοΫ͕ݱΕΔ

  11. ϩδοΫͷॏෳ

  12. ϩδοΫͷॏෳ (&5BQJJUFNT 0, \ lOBNFzzQIQDPOεςοΧʔz  lQSJDFz ^ MFUQSJDFEBUBQSJDF 

    QSJDFQSJDF 
  13. ϩδοΫͷॏෳ w όοΫΤϯυʹଘࡏ͢ΔϩδοΫ͸όοΫΤϯυଆͰӅṭ͢Δ w ϑϩϯτΤϯυ͸ϑϩϯτΤϯυͷؔ৺ࣄʹ๩͍͠ w Ξχϝʔγϣϯ w Ϋϩεϒϥ΢β w

    69
  14. ϩδοΫͷॏෳ (&5BQJJUFNT 0, \ lOBNFzzQIQDPOεςοΧʔz  lOFUQSJDFz  lUBYz 

    lQSJDFz  ^ MFUQSJDFEBUBQSJDF QSJDFOFUQSJDF 
  15. τϥϯβΫγϣϯͰ͖ͳ͍ w αʔόʔଆͷঢ়ଶ͕มԽ͢ΔͷΛࢭΊΒΕͳ͍

  16. τϥϯβΫγϣϯͰ͖ͳ͍

  17. τϥϯβΫγϣϯͰ͖ͳ͍ (&5BQJJUFNT 0, \ lTUPDLz ^ 1045BQJPSEFS 0, \ lJEz

    ^ 1045BQJPSEFSJUFN
  18. τϥϯβΫγϣϯͰ͖ͳ͍ (&5BQJJUFNT 0, \ lTUPDLz ^ 1045BQJPSEFS 0, \ lJEz

    ^ 1045BQJPSEFSJUFN ࡏݿ੾Εൃੜʂ
  19. τϥϯβΫγϣϯͰ͖ͳ͍ w UFMMEPO`UBTLʮίʔώʔͪΐ͏͍ͩʂʯ w ϩδοΫͷӅṭͷҰछͰ͸͋Δʢ0SEFSIBT.BOZ0SEFS*UFNTͰ͋Δ͜ͱ ΛϑϩϯτΤϯυ͸஌Βͳͯ͘ྑ͍ʣ w τϥϯβΫγϣϯ͸αʔόʔ಺Ͱߦ͏͜ͱ͕Ͱ͖Δ

  20. τϥϯβΫγϣϯͰ͖ͳ͍ 1045BQJPSEFS\lJUFN@JETz<>^ ࡏݿ͕͋Ε͹͕ؼͬͯ͘Δ͕ɺͳ͚Ε͹ͱͳΔ

  21. ͜ͷ"1*ɺଞʹͲ͜Ͱ࢖ΘΕ͍͚ͯͨͬʁ w ಉ͡Α͏ͳσʔλΛ࢖͏͔Βͱ"1*Λ͋ͪͪ͜Ͱ࢖͍·Θͨ݁͠ՌɺཁΒͳ͘ ͳͬͨ"1*Λ࡟আͨͯ͘͠΋ଞͷ෦෼ʹӨڹ͕ग़ͦ͏Ͱ࡟আͰ͖ͳ͍

  22. ͜ͷ"1*ɺଞʹͲ͜Ͱ࢖ΘΕ͍͚ͯͨͬʁ

  23. ͜ͷ"1*ɺଞʹͲ͜Ͱ࢖ΘΕ͍͚ͯͨͬʁ (&5BQJBSUJDMFT MJNJUP⒎TFU 0, < \lUJUMFzzBBBz zCPEZzzBBBz^  \lUJUMFzzCCCz zCPEZzzCCCz^

    > (&5BQJBSUJDMFT MJNJU 0, < \lUJUMFzzBBBz zCPEZzzBBBz^  \lUJUMFzzCCCz zCPEZzzCCCz^ >
  24. ͜ͷ"1*ɺଞʹͲ͜Ͱ࢖ΘΕ͍͚ͯͨͬʁ (&5BQJBSUJDMFT MJNJUP⒎TFU 0, < \lUJUMFzzBBBz zCPEZzzBBBz^  \lUJUMFzzCCCz zCPEZzzCCCz^

    > (&5BQJBSUJDMFT MJNJU 0, < \lUJUMFzzBBBz zCPEZzzBBBz^  \lUJUMFzzCCCz zCPEZzzCCCz^ > QBHFʹ͍͚ͨ͠ͲͰ͖ͳ͍ ࢖ΘΕͳ͍CPEZσʔλΛ͍࣋ͬͯΔ
  25. ͜ͷ"1*ɺଞʹͲ͜Ͱ࢖ΘΕ͍͚ͯͨͬʁ w "1*΋431ʹ͠Α͏ w ϑϩϯτΤϯυ͔Βݟͯผͷ༻్ͳΒ"1*΋ผʹ͢Δ w ΋ͪΖΜόοΫΤϯυ಺ͰϩδοΫ͕ڞ௨ͷ෦෼͸·ͱΊΕ͹ྑ͍

  26. ͜ͷ"1*ɺଞʹͲ͜Ͱ࢖ΘΕ͍͚ͯͨͬʁ (&5BQJBSUJDMFT QBHF 0, < \lUJUMFzzBBBz zCPEZzzBBBz^  \lUJUMFzzCCCz zCPEZzzCCCz^

    > (&5BQJMBUFTU@BSUJDMFT 0, < \lUJUMFzzBBBz^  \lUJUMFzzCCCz^ >
  27. O  w αʔόʔαΠυͰҰରଟͷϦϨʔγϣϯΛ࣋ͭΦϒδΣΫτΛऔಘ͠Α͏ͱ͠ ͯɺO ճͷϦΫΤετΛൃߦͯ͠͠·͏

  28. O 

  29. O  (&5BQJDBUFHPSJFT 0, < \lOBNFzz1)1z^  \lOBNFzz4ZNGPOZz^ > (&5BQJBSUJDMFT@DPVOU

    DBUFHPSZ1)1 0, \ lDPVOUz ^ (&5BQJBSUJDMFT@DPVOU DBUFHPSZ4ZNGPOZ 0, \ lDPVOUz ^ ʢOճϦΫΤετʣ
  30. O  w O ΛղܾͰ͖ΔϨΠϠʔʢ42-ʣʹ೚ͤΔ w ܗ͕มΘΔͷͰɺผͷ໊લΛ͚ͭΔ w 2ͦΜͳ͜ͱ͍͍ͯ͠ͷʁϢʔβʔͷϝϯλϧϞσϧͱ߹Θͳ͍Μ͡Όͳ ͍ʁ

    w "1*ͷϢʔβʔ͸ϑϩϯτΤϯυ͔ͩΒɺϑϩϯτΤϯυͷϝϯλϧϞσϧ ͱ%4-ʢ"1*ͷ63- ύϥϝʔλ ϨεϙϯεʣΛ߹ΘͤΑ͏
  31. O  (&5BQJDBUFHPSZ@XJUI@BSUJDMFT@DPVOU 0, < \lOBNFzz1)1z zBSUJDMFT@DPVOUz^  \lOBNFzz4ZNGPOZz zBSUJDMFT@DPVOUz^

    >
  32. ༨ஊղܾυϝΠϯͱ໰୊υϝΠϯͱϝϯλϧϞσϧ w ϑϩϯτΤϯυ͸ղܾυϝΠϯɺόοΫΤϯυ΋ղܾυϝΠϯɺۀ຿͸໰୊υ ϝΠϯ w υϝΠϯۦಈઃܭͷର৅ͱͳΔͷ͸໰୊υϝΠϯ͚ͩͰ͸ͳ͍ w ࠷ऴϢʔβʔͷϝϯλϧϞσϧͱҰக͢Δ࣮૷Λ͍ͯͯ͠͸%#ਖ਼نԽͳΜͯ ͍ͭ·Ͱܦͬͯ΋Ͱ͖·ͤΜ w

    ϢʔβʔͷϝϯλϧϞσϧʹҰகͤ͞Δ΂͖͸%4-
  33.  QIQ @Component({}) export class MyComponent extends OnInit {...} "1*

    #*; 6*69
  34. UIBOLZPV