ãDCI ãªãã¦é¢åãªã ã㧠Service 使ãã°ãããã¸ã®è¿ç
NOTE: æä¸é¨ã«è¿½è¨ãããã¾ãã
ããè¨ããã話ã¨ãã¦ã DCI ãªãã¦å®è£ ãé¢åãªä¸ã«å¤¢ã®å®è£ ã®è©±ããã¦ãããç¾å®è§£ã¨ãã¦ã¯ Service ã¯ã©ã¹ãç¨ãã¦å®è£ ããã°ã·ã³ãã«ãªå®è£ ã«ãªãã®ã ããããããã£ããã®ã¯å¿ è¦ãªãã®ã ãã¨ãããæè¦ã¸ã®è¿çã§ãã
ãããã£ãæ¹å¤ã®æèã®éã Service ã¯ã©ã¹ã¨ããã®ãã©ãã® Service ã¯ã©ã¹ãæãã¦ããã®ãããåé¡ãªã®ã§ããã DDD ã«ããã Service ã§ã¯ãªãããã«æããã®ã§ããããã PofEAA ãªã©ã§èªããã Service Layer ãªã©ãæãã¦ããã¨æããã¾ã(éããªãããè¨ã£ã¦ãã ãã)ã
PofEAA ã«ããã Service Layer(以å¾ã Service ã¨å¼ã¶ãã®ã¯ãã® PofEAA ã«ããã Service ã§ã)ã¯ãã¡ã¤ã³ãªãã¸ã§ã¯ãããã¢ããªã±ã¼ã·ã§ã³ãã¸ãã¯ãåãé¢ããã¨ã主ç®çã¨ãã¦ãã¾ããããã¯ã³ã¼ããµã³ãã«ãè¦ãéã DCI ã«ããã Context ã¨é常ã«é¡ä¼¼ãã¦ããã Context ã®èª¬æãããéã«ããããã Service ã¿ãããªãã®ã ããã¨èª¬æãããã¨ãå¤ããããã¨æãã¾ããããã¯ééãã§ããã Service 㨠Context ã¯ã¹ã¿ã¼ãå°ç¹ãããã¦éããã®ãªã®ã§ãæ··åãã¦ã¯ããã¾ããã
ãããªã¨ã¸ã¥ãªã¨ãã
ãã¦ãä»åã®ä¾é¡ã¯åãã£ãæ°ã«ãªã DCI ããããªã¨ã¸ã¥ãªã¨ããç·¨ãå ã«è©±ããã¦ããã¾ããã¿ã¤ãã«ãé·ãããã®ã§ããã§ã¯ããã¸ã¥ãªã¨ããã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦è©±ã¾ãããã
ããã¸ã¥ãªã«ããããã¡ã¤ã³ãªãã¸ã§ã¯ãã¯è¨ãããã㪠Actor ã§ããå½¹è
ã¨ãããã¼ã¿ã¢ãã«ã§ãããæ¬æ¥ã§ããã° Actor ã«ã¯å¹´é½¢ãæ§å¥ãªã©ã®ãã¼ã¿ãä»ä¸ããã¦ãããã®ãã¨æãã¾ãããä»åã¯å²æãã¾ããã¨ã«ããå½¹è
ã®ã¢ãã«ããããå½¹è
ã¯åããªãã¦ã¯ãªããªãã®ã§ã #say
ã¨ããã¡ã½ãããæã£ã¦ãã¾ãã
ããã¸ã¥ãªã¢ããªã±ã¼ã·ã§ã³ã§ã¯ããããªã¨ã¸ã¥ãªã¨ããã®1ã·ã¼ã³ãåç¾ããã®ãã¢ããªã±ã¼ã·ã§ã³ã®ä»äºã§ãã®ã§ããããªå½¹ã® Actor ã¨ã¸ã¥ãªã¨ãã役㮠Actor ãå¿ è¦ã«ãªãã¾ãã
ããã§åé¡ã«ãªãã®ã¯ãããªã Romeo ã¢ãã«ã¨ Juliette ã¢ãã«ã«ãªã£ã¦ããªãã®ããã§ããããã¸ã¥ãªã¢ããªã±ã¼ã·ã§ã³ã«ããã主ç®çã¯ãªããªã®ããã¨ããæ ¹åºã®é¨åãåé¡ã«ãªã£ã¦ãã¾ãã
åãããã¸ã¥ãªãµã³ãã«ãæ¸ããæããããã®ã³ã¼ãã¯ããã¢ããªã±ã¼ã·ã§ã³ã®ä¸é¨ã¨ãã¦æ¸ããããã®ã§ãããã¨ããæ³å®ã§æ¸ãèµ·ãããã¾ãããããã¯ãèå°åçã¢ããªã±ã¼ã·ã§ã³ã§ããèå°åçã¢ããªã±ã¼ã·ã§ã³ã¯ã·ããªãªãã³ã¼ãã¨ãã¦æã¡ãç¹å®ã®ã·ã¼ã³ãå½¹è ãå ¥ãæ¿ãã¦åçãããã¨ãåºæ¥ãã¨ããã¢ããªã±ã¼ã·ã§ã³ã§ãããããããã«ã²ã¼ã ã®ç»é¢ã§ããã£ã©ãå ¥ãæ¿ããªããç¹å®ã®ã·ã¼ã³ãåçã§ãããã¨ãã£ããããªã¢ããªã±ã¼ã·ã§ã³ãæ³å®ãã¦ãã¾ããã
ãªã®ã§ãå½¹ã§ãã Romeo åã³ Juliette ã¯ã¢ãã«ã§ã¯ãªãããã¾ã§æ¯ãèãã§ããRomeo ã Juliette ããã¼ã¿ãæãããã¢ããªã±ã¼ã·ã§ã³ä¸ã®é½åã«ããã©ã®ãããªå°è©ãåããã«ãã£ã¦åºå¥ããã¾ããRomeo ã Juliette ãããã¼ã¿ãæã£ãã¢ãã«ã¨ããããã¯ç¹å®ã®å°è©ã®éåã§ããã¨æããã¹ãã§ãã
Service ã«ããããã¸ã¥ãªã®å®è£
ã§ã¯ãå®éã« Service ã§ããã¸ã¥ãªã¢ããªã±ã¼ã·ã§ã³ãå®è£ ããã¨ãªãã¨ãã©ã®ãããªå®è£ ã«ãªãã®ã§ãããããã·ããªãªãã¼ã¿ã¯å¤é¨ããã®å ¥åãªã©ã§ã¯ãªããã¢ããªã±ã¼ã·ã§ã³ä¸ã«ãã¿æ¸ãã§å±éããã¦ãã¾ãã®ã§ããããªã¨ã¸ã¥ãªã¨ãããåãå°è©ã®å 容ã¨ããã®ã¯ã¢ããªã±ã¼ã·ã§ã³ã¬ã¤ã¤ã®è©±ã«ãªãã¾ãã
ãã¡ã¤ã³ãªãã¸ã§ã¯ãã¨ãã¦ã¯ Actor ã¯ä»ã®ã¨ããéä¸è¶³ãªãæ©è½ãæã£ã¦ããã®ã§ãã¢ããªã±ã¼ã·ã§ã³ã¬ã¤ã¤ã®æ¯ãèããæ½åºã㦠Service åããã¨ãªãã¨ã以ä¸ã®ãããªã³ã¼ãã«ãªãã§ããããã
class Scene03Service def initialize(romeo, juliette) @romeo = romeo @juliette = juliette end def execute # ã¸ã¥ãªã¨ããã«ããåããã @juliette.say <<-EOS O Romeo, Romeo! wherefore art thou Romeo? Deny thy father and refuse thy name; Or, if thou wilt not, be but sworn my love, And I'll no longer be a Capulet. EOS # ãããªã®å½æ @romeo.say "Shall I hear more, or shall I speak at this?" # ã¸ã¥ãªã¨ããã®æé¡ @juliette.say <<-EOS Tis but thy name that is my enemy; Thou art thyself, though not a Montague. What's Montague? it is nor hand, nor foot, Nor arm, nor face, nor any other part Belonging to a man. O, be some other name! What's in a name? that which we call a rose By any other name would smell as sweet. EOS end end
åãå 容ã«ã¤ãã¦ã¯ã¢ããªã±ã¼ã·ã§ã³å´ã®é½åã§ãã®ã§ããã¡ã¤ã³ãªãã¸ã§ã¯ãã«ã¯ãªããã¾ãããã§ãã®ã§ãæç´ã«å®è£ ããã¨ãã®ãããªã³ã¼ãã«ãªããã¨æããã¾ã(ããããã®èªèãééã£ã¦ããå ´åã¯ãææããã ããã¨ãããããã§ã)ã
ä»ã¯ããã¦èªã¿ã«ãããªããããªä¾é¡ãåºãã¦ãã¾ãã®ã§ãããªãæ£æçãªçµæã«ãªã£ã¦ããã¨ã¯æãã¾ããã Service ã«ããå®è£ ã¯ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ããæç¶ãåçãªã³ã¼ãã«å¤å®¹ããã¦ããã®ã§ã¯ãªãããã¨ããå±æ§ã ãä¼ããã°å¹¸ãã§ããæç¶ãåçã§ãããã¢ããªã±ã¼ã·ã§ã³ãåãã°ããã®ã§ãããã¨ããã話ã§ããããè¨è¨ææ³ãªã©è°è«ããä½å°ããªãã®ã§ãããã§ããã¾ãã§ãã
ãã®ä¾ã§ã¯ãããããã¨ã¯ããã»ã¼ãäºãã«è¨ãã£ã±ãªãã®ç¶æ³ã§ãããããªãã¸ã§ã¯ãéã§ä½ããã®ããã¨ãããããã¨ãã£ãç¶æ³ã«ã¯ãªã£ã¦ãã¾ãããã Actor ã«ä¾ãã° #left_hand
ãªã©ã® Attribute ããããæã«æã£ããªãã¸ã§ã¯ããããã¨ãããããªã©ã®ã·ã¼ã³ãå®è£
ãããã¨ãããããã®æã¯ããæç¶ãåãããã³ã¼ãã«ãªããã¨æããã¾ãã
# ã¸ã¥ãªã¨ãããæã«æã£ãæ¯ããããªã«æ¸¡ã @romeo.left_hand = @juliette.left_hand @juliette.left_hand = nil
ã³ã¼ãä¸ã§ã¯æ£ããç®çã©ããã«ã¸ã¥ãªã¨ããã®æå ã®æ¯ããããªã®æå ã«ããã£ã¦ããã®ã§ãããããã¯åä¸é²è¡ãä¸ååæ ãã¦ãã¾ããããã¸ã¥ãªã¨ãããæ¯ããããªã«æ¸¡ããã¨è¨ã£ã¦ããã®ã§ãããã主èªã¯ã¸ã¥ãªã¨ããã§ããã¹ããªã®ã«1è¡ç®ã®ä¸»èªã¯ãããªã§ãããã³ã¡ã³ãããªããã°ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦ãã®åç §ã®ç§»åãã©ããã£ãæå³ãããæã£ã¦ããã®ãç解ããã®ã¯å°é£ã§ãããã
ãã¡ãããService ãæªã訳ã§ã¯ãªããä»åã®ä¾ã¯æ£æçã« Service ã§è¡¨ç¾ãã«ããã³ã¼ããé¸ãã§ããã¤ææãã«è¡¨ç¾ãã¦ããã®ã§ãããã«ãããªã£ã¦ãã¾ããPofEAA ã«é è©£ãæ·±ãããã§ããªãã®ã§ãåãåéããã¦ããããããã¾ãããããããæ㯠ItemPassingService ã§ãä½ã£ã¦ã渡ãå´ã¨åãåãå´ã«åããã¦ãªãã¸ã§ã¯ããããã¨ããããããªå¦çãå ¥ããã¨ã«ãªããã§ããããã
DCI ã«ããæ¯ã®åã渡ã
ä¸æ¹ DCI ã«ããã¦æ¯ãåã渡ããããªã·ã¼ã³ãå¿ è¦ãªå ´åã¯ããããã以ä¸ã®ãããªæ¸ãæ¹ã«ãªãã¾ãã
module Juliette def pass(target) target.left_hand = self.left_hand self.left_hand = nil end end class PassingPoisonContext def execute @juliette.pass(@romeo) end end
å ã»ã©ã®ä¾ã«ãã£ãå¦çã Juliette Role ã®ã¡ã½ããã«ãªããContext ã§ã¯ãã®ã¡ã½ãããå¼ã³åºãã ãã«ãªãã¾ãããã³ã¼ãéã¨ãã¦ã¯å¢ããã®ã§ãããã¢ããªã±ã¼ã·ã§ã³ã«æå¾ ããã¡ã³ã¿ã«ã¢ãã«ãã³ã¼ãä¸ã«æå½±ãããéãå¢ãããã¨ã¯ãç解ããã ããã§ããããã
DCI ã¯å¥ã« Role ã extend ã㦠unextend ãããã¨ãããããªé¨åãæ¬è³ªã§ã¯ããã¾ãããéçºã¨ãã¦æ¥½ã«ãªããã DCI ãæ¡ç¨ãããã¨ããã®ãééã£ã¦ããã®ã§ã¯ãªããã¨æã£ã¦ãã¾ãã
DCI ã«ãã£ã¦ã³ã¼ãã£ã³ã°ãç°¡ç¥åããããã¨ããã¨ãããã¯ãããããã¾ããªãã§ãããããã³ã¼ãã®è¦éããã¨ããç¹ã«ãã¦ãå®éã«åèªèº« DCI ã§æ¥åã§æºããè¦æ¨¡ã®ã¢ããªã±ã¼ã·ã§ã³ãå®è£ ãããã¨ãããã¾ãããããããã¾ããããããããå¢ãããã¼ã«ã¨ã³ã³ããã¹ãã«ãã£ã¦ã1ã¤ã®ã³ã¼ããã¡ã¤ã«ãè¦ã¦ææ¡åºæ¥ããã¨ã¯æ¸ãã®ã§ã¯ãªããã¨æã£ã¦ãã¾ããã¾ããç¾å®çãªå©ç¨ãèããæãä¸æçãªæ¯ãèãããªãã¸ã§ã¯ãã«æ³¨å ¥ããã®ã¯ã©ãããã®ããã¨ããé¨åã«ã¤ãã¦ã¾ãæ¤è¨ããå¿ è¦ããããç¾å¨ã®ããã°ã©ãã³ã°ç°å¢ã«ããã¦ãæ¡ç¨ãããªããã©ãã¤ã ã ãããªã¨ããæ°ã¯ãã¦ãã¾ãã
ããã§ãåã¯ãã³ã¼ãä¸ã«æå½±ãããã¡ã³ã¿ã«ã¢ãã«ãå¤ããªãã°ãªãã»ã©ã³ã¼ãã®ä¿å®æ§ã¯ä¸ãã£ã¦ããã¯ãã§ããã¨ä¿¡ãã¦ãã¾ãããææªãã³ã¼ãã ãã§ã¡ã³ã¿ã«ã¢ãã«ãç解åºæ¥ããããªæ¥ãæ¥ãã®ã§ããã°ãããã¯ã·ããªãªãæ¸ãã°ã¢ããªã±ã¼ã·ã§ã³ãåºæ¥ä¸ãã£ã¦ããã®ã¨å義ã§ããã®ã§ã¯ãªããã¨ããæã£ã¦ãã¾ãã
ã¡ã³ã¿ã«ã¢ãã«ãå¢ãã
人ã¯ã¢ããªã±ã¼ã·ã§ã³ã«ä½ããæå¾ ãã¦æä½ãå ¥åãã¾ããATM ã§ããã°ãèªåã®å£åº§ãããéãæå ã«åºã¦ãããã¨ããã¡ã³ã¿ã«ã¢ãã«ã§ãããå®éã®ã¢ããªã±ã¼ã·ã§ã³å ã§ã®å®è£ ã§ã¯ããæä½è ã®å£åº§ã®ç¾éæ®é«ãå ¥åå¤åæ¸å°ããããATM é庫å ã®ç¾éãå ¥åå¤åéåºãããã¨ããå®è£ ããªããã¦ãããã³ã¼ãä¸ã®è¡¨ç¾ã¨ã¦ã¼ã¶ã¼ã®ã¡ã³ã¿ã«ã¢ãã«ã¯ä¸è´ãã¾ããã
ã¡ã³ã¿ã«ã¢ãã«ã«ã³ã¼ããè¿ã¥ãã¦ããã¨ããä½æ¥ã¯ãèªèº«ã®ã¢ããªã±ã¼ã·ã§ã³ã¸ã®ç解ãåä¸ãããã¨ã¨ãã«ããã¡ã¤ã³ã¨ãã¹ãã¼ãããå¾ãç¥èãããã³ã¼ãä¸ã«æå½±ãããããªããã¨ã ã¨æã£ã¦ãããããããã DCI ã®å©ç¹ã§ããæ¡ç¨ãã¹ãçç±ã ã¨æã£ã¦ãã¾ãã
ã¨ãããã¨ã§
è¿çã¯ä»¥ä¸ã§ãã
DCI æ´¾ãããã Service æ´¾ãããããã³ããããã¨æãã®ã§ãçªã£è¾¼ã¾ã次第修æ£ãã¦ããæåã§ãã
ãããã Service ã®ä¾
monzou ããã«ããç¾å®ç㪠Service ã®ã³ã¼ãã®ä¾ãæ¥ãã帰çä¸ã«ãããã¨ããããã¾ãã
ã¾ãã¯ããã«è¨ã£ã¦ããã¨ãå㯠Service ãã DCI ã®æ¹ãåªãã¦ãã¨ã¯æã£ã¦ããããåã«å㯠DCI ã好ãã§ãããããã§ãããªãã§ãããã ããã¾ãã«ã DCI ã«å¯¾ã㦠Service ã§ããã DCI ã¯è¦ããªããã¨è¨ããããã¨ã(å人ççµé¨ä¸)å¤ãã£ãã®ã§ãããã Service ã®è©±ã¯ãããã§ãããã¨ããæãã§æ¸ãå§ããã®ã§ãããããããã¨ã³ããªã§ Service ãããè¯ãç¥ããã¨ã«ãªãã¨ããã®ã¯é¢ç½ãæãã§ãã
ãã¦ãæ¬é¡ã® monzou ããã«ããã£ãä¾ãè¦ãã¨ãScene ããã¡ã¤ã³ãªãã¸ã§ã¯ãã«ãªã£ã¦ãããåã®ã³ã¼ãä¾ã¯ Service ã®ã³ã¼ãä¾ã¨ãã¦å®ã«ä¸é©åã ã£ããã¨ããããã¾ãã
ãã¡ã¤ã³ãªãã¸ã§ã¯ãã¨ã㦠Scene03 ãå®è£ ãã¦ã Service ããã¯ãã® Scene ãªãã¸ã§ã¯ããå®è¡ããã ããã¨ããå½¢ã«ãªã£ã¦ããããã¤ãã¡ã³ã¿ã«ã¢ãã«ã®æå½±ã«ã¤ãã¦ãåã®æ¸ãã DCI ã®ä¾ã¨ä¸åéè²ããã¾ããã
ã¦ããã大ä½ãã£ã¦ããã¨ä¸ç·ãªããããªãã®ï¼ã¿ãããªæ°æã¡ã«ãªãã¾ããããããããã ãã¨ããæãã§ãããã®æã® Scene ã®å®è£ ã®éãã¯ã Delegation ã«ãã£ã¦å®è£ ããã¦ããããããã¨ã extend ã«ããæ¡å¼µãã®éããããã§ãã
Jim Copelien æ°ã«ããã°ãDCI ã«ãã㦠Role ã Delegation ã«ãã£ã¦å®ç¾ãã¹ãã§ãªãã®ã ããã§ããçç±ã¨ãã¦ã¯ã Context ã®ä¸ã«å ¥ã£ãã¨ãã¦ãã¨ãã Data ã¯å¤ãã£ãããã§ã¯ãªãã®ã§ãåä¸ã®ãªãã¸ã§ã¯ãã§ããã¹ãã§ãããä½ã㧠Wrap ãããå¥ã®ãªãã¸ã§ã¯ãã§ããã¹ãã§ã¯ãªããã¨ããææ³ããããçç±ã ããã§ãã
éãè¨ãã°ãã®ç¨åº¦ããéãããªãã®ã§ããDCI ã§ã Service ã§ããã©ã£ã¡ã§ãããããããªãï¼ãã¨ãªãã¨è¿çã¯ãã¯ããã«ãªãã¾ããã¨ã¯ãããä¸è¨ã®ããã°è¨äºã ãã ã¨åã Service ãã DCI ã®æ¹ãããï¼ã¨è¨ã£ã¦ããããã«ããèªããªãã®ã§ããâ¦â¦åã«å¥½ããªãã®ã¸ã®ãã¤ã¢ã¹ãããã£ã¦ããã ãã§ãã Service 使ãã°ããã¨ãã£ã人ãã¡ã Service ã好ããªã ã㧠DCI ã¯ã¾ã£ããæå³ããªãã¨æã£ã¦ãã人ã°ã£ãããããªãã®ããããã¾ããã
ã¾ããæç¶ãçã«ãªãã®ã¯ãã©ã³ã¶ã¯ã·ã§ã³ã¹ã¯ãªããã ããã¨ããã®ãã¾ã£ãããã®éãã§ãããå®å ¨ã«åéãã§ããã
ããããæå³ã§è¨ãã¨ãå¤ãªè©±ã§ãã DCI ã«ããã Context ã¯ãã©ã³ã¶ã¯ã·ã§ã³ã¹ã¯ãªããçã§ã¯ããã¾ããã¦ã¼ã¶ã¼ã®ã¦ã¼ã¹ã±ã¼ã¹ã®ã¹ãã¼ãªã¼ãé ã«æ¸ãã¦ãããã¨ã«ãªãã®ã§ã大ã㪠Context ã«ãªãã°ããã ãé·ãã¹ãã¼ãªã¼ã並ã¶ãã¨ã«ãªãã¾ããããã¸ã¥ãªã®ä¾ã§è¨ãã°ã1ã·ã¼ã³ãã1å¹ã«ãªã£ããã©ãã ãã®éã®å°è©ã®ç¾ åã並ã¶ãã â¦â¦ã¨ããæãã§ãããããããæ㯠Context ãã®ãã®ãåå²ãã¦å Context ãä½ã£ã¦ãããã¨ã«ãªãã¨æãã¾ãããã±ã£ã¨è¦ã®ã³ã¼ãã§æç¶ãçã«æ ãã®ã¯ DCI ãªããããªãããªãã¨ããæ°ã§ãã¾ããã¦ã¼ã¶ã¼ã®æ³åããã¡ã³ã¿ã«ã¢ãã«ãç¾ åãã¦ãããã¨ã«ãªãã®ã§ãã¾ããããªãããªãã¨ããæãã§ããã
ã¨ã¾ã話ãããã¦ããã®ã§æ»ãã¦ããã¨ããããã Service ã®å®è£ ãèªãéããDCI ã§å®ç¾ãã¦ãããã㯠Service ã®å±¤ã§ã¯ãªããã¡ã¤ã³ãªãã¸ã§ã¯ãã®å±¤ãªã®ã§ã¯ï¼(ãããå®éãããã¨ããã¨å¤åã¡ãã£ã¨éãã®ã§ãã)ã¿ãããªæ°ã«ãªã£ã¦ããã®ã§ãService å ¨ç¶æªããªãããããåã¯ãªã㧠DCI ã¨æ¯è¼ã㦠Service ãå§ãããã¦ããã®ã ãããâ¦â¦ã¨ããã®ãä»ã®ã¨ããã®å¿ä¸ã§ãã
ã¾ã 俺ã«åãããï¼ã¨ããããããããã®ããã£ã¦ã ãªããªã©ã®å ´åã¯ãé£çµ¡ãã ãããmonzou ãããæ¬å½ã«ãããã¨ããããã¾ãã