ðã³ãã³ãã»ã¯ãšãªåé¢ïŒ Commandâquery separation CQSïŒãã¹ãŠã®ã¡ãœããã¯ãã¢ã¯ã·ã§ã³ãå®è¡ããã³ãã³ãããåŒã³åºãå ã«ããŒã¿ãè¿ãã¯ãšãªã®ã©ã¡ããã§ããã¹ãã§ãäž¡æ¹ã§ãã£ãŠã¯ãªããªã
ã³ãã³ãã»ã¯ãšãªåé¢ïŒCommand Query Separation: CQSïŒã¯ããªããžã§ã¯ãæåèšèšã®ååã®1ã€ã§ãBertrand Meyerã«ãã£ãŠæå±ãããŸããããã®ååã¯ããªããžã§ã¯ãã®æäœã«é¢ããæ¹æ³è«ãšããŠã次ã®2ã€ã®äž»èŠãªæäœãæ確ã«åºå¥ããããšãæšå¥šããŸãïŒ
ã³ãã³ãïŒCommandsïŒ: ãªããžã§ã¯ãã®ç¶æ ãå€æŽããæäœãè¿ãå€ãæããªãïŒvoidãŸãã¯åçã®ãã®ïŒã
ã¯ãšãªïŒQueriesïŒ: ãªããžã§ã¯ãã®ç¶æ ãåç §ãŸãã¯ååŸããæäœããªããžã§ã¯ãã®ç¶æ ãå€æŽããªãã
ãã®ååã®äž»ãªèŠç¹ã¯ãåäžã®æäœãã³ãã³ããšã¯ãšãªã®äž¡æ¹ã®åœ¹å²ãæãããªãããã«ããããšã§ããã€ãŸããç¶æ ãå€æŽããæäœã¯ãããã«é¢ããæ å ±ãçµæãè¿ããŠã¯ãããŸãããåæ§ã«ãæ å ±ãååŸããæäœã¯ããªããžã§ã¯ãã®ç¶æ ãå€æŽããŠã¯ãããŸããã
ã³ãã³ãã»ã¯ãšãªåé¢ã®å©ç¹
äºæž¬æ§: CQSã«åŸã£ãã·ã¹ãã ã¯ãåäœãäºæž¬ãããããªããŸãããªããªããããã¡ãœãããç¶æ ãå€æŽããã®ãããããã¯åã«æ å ±ãè¿ãã®ããæ確ã«ç¥ãããšãã§ããããã§ãã
åå ¥æ§: ç¶æ ãå€æŽããªãã¯ãšãªã¡ãœããã¯ããã°ãã°åå ¥å¯èœã§ããããããã«ãã¹ã¬ããã®ç°å¢ã§ã®å®è¡ã容æã«ãªããŸãã
å¯èªæ§ãšä¿å®æ§: ã¯ãšãªãšã³ãã³ããåé¢ãããŠãããšãã³ãŒãã®æå³ãæ確ã«ãªããããã«ãã£ãŠã³ãŒãã®èªã¿ããããä¿å®æ§ãåäžããŸãã
ã³ãã³ãã¯ãšãªãæããæ°åŒ
CQSãæ¡çšããäž»ãªå©ç¹ã¯ãå¯äœçšã®ç®¡çãšäºæž¬å¯èœæ§ã®åäžã§ããæ°åŒã§ãããè¡šçŸããã«ã¯ãã·ã¹ãã ã®ç¶æ ãæ°åŠçãªéåãšããŠã¢ãã«åããã³ãã³ããšã¯ãšãªã®æäœãé¢æ°ãšããŠè¡šçŸããããšããå§ããããšãã§ããŸãã
ç¶æ Sãèããã³ãã³ããé¢æ°C:SÃAâSïŒããã§Aã¯ã¢ã¯ã·ã§ã³ã®éåïŒãã¯ãšãªãé¢æ°Q:SâVïŒããã§Vã¯å€ã®éåïŒãšã¢ãã«åããŸãã
ã³ãã³ãã¯ãšãªåé¢ã®å©ç¹ã¯ã次ã®ãããªæ§è³ªãæã€ã·ã¹ãã èšèšã«çŸããŸãïŒ
äºæž¬å¯èœæ§ãšåçŸæ§: Q(S)ã¯ãäžããããç¶æ Sã«å¯ŸããŠåžžã«åãçµæVãè¿ããŸããããã¯ã¯ãšãªãç¶æ ãå€æŽããªããããå¯äœçšããªãããšãæå³ããŸãã
å¯äœçšã®åé¢: C(S,A)ã¯æ°ããç¶æ â²Sâ²ãçæããŸããããã®æäœãã¯ãšãªã®çµæã«çŽæ¥åœ±é¿ãäžããããšã¯ãããŸããïŒã³ãã³ãã®å®è¡ååŸã§ã¯ãšãªãå®è¡ããå Žåãé€ãïŒããã®ããã«ãå¯äœçšã¯ã³ãã³ãã«ãã£ãŠã®ã¿åŒãèµ·ããããã¯ãšãªæäœã«ãã£ãŠäºæãã¬ç¶æ å€åãé¿ããããšãã§ããŸãã
ãã®èª¬æã¯æ°åŒã§çŽæ¥çãªãè¡šçŸããšããããã¯ãCQSã®æŠå¿µãæ°åŠçãªçšèªã§èª¬æããŠããŸããCQSã®å©ç¹ã¯ãããã°ã©ã ã®ç解ãä¿å®ããããã°ã容æã«ãªãããšã«ãããããçŽæ¥çã«ãœãããŠã§ã¢ã®å質ãšéçºã®å¹çæ§ã«é¢é£ããŸãã
å¯äœçšãèµ·ããå Žåã®æ°åŒãèããã«ã¯ãç¶æ ã®å€æŽãèªã¿åãæäœïŒã¯ãšãªïŒã«åœ±é¿ãäžãããããªã·ã¹ãã ãã¢ãã«åããå¿ èŠããããŸããå¯äœçšã¯ãããæäœãã·ã¹ãã ã®ç¶æ ãå€æŽãããã®çµæãšããŠä»ã®æäœã®çµæã«åœ±é¿ãäžããå Žåã«çºçããŸãããã®ãããªå Žåãã¯ãšãªæäœèªäœãç¶æ ãå€æŽãããããããã¯ã³ãã³ããã¯ãšãªã®çµæã«éæ¥çã«åœ±é¿ãäžããããšããããŸãã
以äžã®ãããªã¢ãã«ãèããŸãïŒ
å¯äœçšã䌎ãå Žåãã³ãã³ãCãŸãã¯ã¯ãšãªQãç¶æ Sãå€æŽããããšã«ãããåŸç¶ã®æäœçµæãå€ããããšããããŸããã€ãŸããã³ãã³ããã¯ãšãªã®å®è¡ã¯ãã·ã¹ãã ã®ç¶æ ã«åœ±é¿ãåãŒãããã®çµæãåŸç¶ã®ã¯ãšãªã®çµæãå€ããå¯èœæ§ããããŸãã
å¯äœçšãå«ãã¯ãšãªã®å Žåã次ã®ãããªé¢æ°â²Qâ²ãèããããšãã§ããŸãïŒ
ãã§ãâ²Qâ²ã¯ç¶æ ãå€æŽãïŒSããæ°ããç¶æ â²Sâ²ãžïŒãåæã«å€Vãè¿ããŸãããã®é¢æ°ã¯ãã¯ãšãªæäœãå¯äœçšãæã€ïŒç¶æ ãå€æŽããïŒå Žåã®æ¯ãèãã瀺ããŠããŸãã
ãŸããã³ãã³ããå¯äœçšãåŒãèµ·ããå Žåãã³ãã³ãã®åŸã«ç¶ãã¯ãšãªã®çµæãç°ãªãå¯èœæ§ããããŸããäŸãã°ãã³ãã³ãCã®å®è¡åŸã«ã¯ãšãªQãå®è¡ãããšãç°ãªãçµæãåŸãããããšããããŸãïŒ
ãã®åŒã¯ãã³ãã³ãCã®å®è¡ãç¶æ
Sãå€æŽãããã®çµæãšããŠã¯ãšãªQã®çµæãå€ããããšã瀺ããŠããŸããããã¯å¯äœçšã®äžäŸã§ãã
å¯äœçšãå«ãã·ã¹ãã ã§ã¯ãæäœã®é åºãçµæã«å€§ãã圱é¿ãããããããã°ã©ã ã®äºæž¬æ§ãšåçŸæ§ãäœäžããããšãäžè¬çã§ããããã¯ãç¹ã«è€éãªã·ã¹ãã ã䞊è¡æ§ãé¢äžããå Žåã«ããããã°ãä¿å®ãå°é£ã«ããŸãã
ãé¡ãèŽããŸã