[tech]GUI-MVCã¨Web-MVCã®éã
ä¸é¨ã§MVCè°è«ãæµè¡ã£ã¦ããã®ã§ãèªåã®ããã«Smalltalkç±æ¥ã®MVC(以ä¸ãä¸è¬åãã¦GUI-MVCã¨å¼ã³ã¾ã)ã¯Web-MVCã¨ã©ãéãã? ã¨ããç¹ã«ã¤ãã¦ã¾ã¨ãã¦è¦ã¾ãããçªã£è¾¼ã¿ã¯æè¿ã
ãã¨æ¬ç¨¿ã§ã¯ãã¡ã¤ã³ã¢ãã«è²§è¡çæ¹å¤ã¨ãã¯å
¨ãçãè¾¼ã¾ãªããããã¯å°ãéãã¬ã¤ã¤ã¼ã®è©±ãªãã§ãã
0. VCã¯å¤§æµã®å ´åãç·å¯ã«çµã³ã¤ãããã¢ã§ãã
GUI-MVCã§ã¯View-Controller(以ä¸VCãã¢)ã¯ä¸å¯åã®ãã¢ã ã¨ããã¦ãã¾ããæ
å ±ã®å
¥å(ããã³å¶å¾¡)ã¨åºåã§ãããããäºãå¼·ãä¾åããã®ã¯ãããã¾ãã§ãããMicrosoftã®MFCã¨ãJavaã®Swingã§ã¯VCã¯ã²ã¨ã¤ã®ã³ã³ãã¼ãã³ãã¨ãã¦æ±ã£ã¦ãã¾ã(Document-Viewãã¿ã¼ã³ã¨ãå¼ã°ãã¾ã)
ãã ããã®ç¹ã«ã¤ãã¦ã¯Web-MVCã§ããããªã«å¤ãããªãããã
1. GUI-MVCã®View-Controllerãã¢ã¯åä½ãéã
å ã»ã©è¿°ã¹ãããã«GUI-MVCã®VCãã¢ã¯ããã種ã®ã³ã³ãã¼ãã³ããç»é¢ã®é¨åã§ãããªã¹ããã¼ã¿(Model)ã表示ããListView+Controllerã¨ãã表形å¼ã®ãã¼ã¿ã表示ããTableView+Controllerã¨ããWebã§ã¯MVCã¯ä¸ç»é¢ãã¨ã«VCãã¢ãå²ãå½ã¦ãããã¾ãããGUI-MVCã§ã¯ãã£ã¨ç´°ããé¨åã®åä½ã§VCãã¢ãåå¨ãã¾ãã
ããã¯Web-MVCã¨ã¯ããªãéãã¨ããã§ããWebã®ä¸çã§ã¯ãä¸ç»é¢ãããå°ããç»é¢é¨åã¯å®è³ªåå¨ããªãããåçãªã®ã ! ã¿ãããªé ç¥è§£çã¯ããã®å ´åä¸é©åã§ããã
2. GUI-MVCã®VCãã¢ã¯å ¥ãåã«ãªã
TableView+Controllerããå®ã¯TableHeaderView+Controllerã¨è¤æ°ã®TableRowView+Controllerã§æ§æããã*1ãã¨ãã£ãå ·åã«VCãã¢ããããè¤éãªã³ã³ãã¼ãã³ãã®é¨åã«ãªããã¨ãããã¾ãã
ãªã¹ããã½ã¼ã¹ãã¥ã¼ã¢ã®ãããªåç´ãªã³ã³ãã¼ãã³ããããã·ã¹ãã ãã©ã¦ã¶ã®ãããªè¤éãªé¨åãçã¾ããããã¾ããã¤ã¾ãåå²çµ±æ²»ã®è¦æ¬ã®ãããªå½¢ã«ãªãã¾ããã(åå²çµ±æ²»ã«ã¯ãããããªåãå£ããããã§ã)
ãã ãå ¥ãåã«ãªã£ãVCãã¢ã¨Modelã®é¢ä¿ã«ã¤ãã¦ã¯é常ã«æ°ã«ãªãã¨ããã§ããVCãã¢ãå ¥ãåã«ãªã£ãå ´åãModelãå ¥ãåã«ãªã£ã¦ããã®ã? ããã¨ãModelã¨VCãã¢ã®æ§é ã¯å¥ã ãªã®ããããã¯ç¢ºãã«åé¡ã«ãªãã¨ããã§ããã¾ãããä»åã®è°è«ã¨ã¯å¥ä»¶ãªã®ã§åé¢ãã¾ã
3. GUI-MVCã®VCãã¢ã¯æ±ç¨ã³ã³ãã¼ãã³ããç®æã
Web-MVCã§ã¯Modelã®åå©ç¨æ§ã°ãã宣ä¼ããã¾ãããGUI-MVCã§ã¯VCãã¢èªä½ã®åå©ç¨æ§ãéè¦ããã¾ããã³ã³ãã¼ãã³ããªãã ããåå©ç¨ãããã§ãããã
VCãã¢ãæ¯åç¹å®ã®ã¢ãã«åãã«å®è£
ããã®ã§ã¯ãªããVCãã¢ãèªåã«é©åããã¤ã³ã¿ãã§ã¼ã¹ãæã¤ã¢ãã«ã ãæ±ãããã«ãã¾ãããã¡ãã¡VCãã¢ãç¶æ¿ãã¦å®è£
ãããããã«åå©ç¨å¯è½ã«ãªãã¾ããSmalltalkçéã§ã¯ãã©ã¬ãã«MVCã¨å¼ã°ãããã®ã§ãã
ãã ãModelèªä½ã®åå©ç¨æ§ãé«ããã¨ããå½åã®ç®çã«ã¯çç¾ãããã§ããããã®åé¡ã«å¯¾è±¡ããããã«Smalltalkçéã§ã¯MMVCã¨å¼ã°ããMVCã®æ¹è¯çã®ãã¿ã¼ã³ãèæ¡ããã¾ãããModelããApplicationModelã¨DomainModelã«åå²ããã¨ããæ¹å¼ã§ãããã©ã¬ãã«MVCã®å®ç¾ã«ã¯MMVCãä¸å¯æ¬ ã¨ããã®ã俺ã®ç解ã§ãã(ãã£ã¦ãã ããã?)ã
Javaã®Swingã§ããä¾ãã°JTableã¯TableModelã¤ã³ã¿ã¼ãã§ã¼ã¹ãå®è£ ããã¢ãã«ãè¦æ±ãã¾ããéçºè ã¯ãTableModelãå®è£ ããApplicationModelãéçºãããããDomainModelã«ã¢ã¯ã»ã¹ããã¨ããããæ¹ã§å¯¾å¦ãã¦ãã¾ããã¤ã¾ãAdapterãã¿ã¼ã³ã§ããã
4. GUI-MVCã§ã¯Observerãã¿ã¼ã³ãå©ç¨ãããã¨ãå¤ã
ããã¯ã¿ããªç¥ã£ã¦ããã¨ã ããé·ã æ¸ãã¾ãããããModelã®å¤æ´ãViewã«åæ ãããããã«ãObserverãã¿ã¼ã³ãå©ç¨ãããã¨ãå¤ãã§ããã¾ãè¤æ°ã®VCãã¢ããæ§æããããããªè¤éãªã³ã³ãã¼ãã³ããçç¾ãªããªã¢ã«ã¿ã¤ã ã§æ å ±ã表示ãããããã«ã¯ãObserverã¨ãMediatorãã¿ã¼ã³ããã«æ´»ç¨ããå¿ è¦ãããã¾ãã(GoFæ¬ã«ããããä¾ãè¼ã£ã¦ã¾ããã)
çµè«
ã¨ãé·ã è¿°ã¹ã¾ãããWeb-MVCã¨GUI-MVCã¯å ¨ç¶éãã®ã§ããã®ãã¿ã¼ã³ãå¿ è¦ã¨ãªãå¶ç´æ¡ä»¶ããå¾ãããã¡ãªãããå ¨ãéãã¨ãããã¨ã§ãã
ã ããã¨ãã£ã¦Web-MVCã¯ã¯ã½ã ãªã¼ã¨è¨ãã¤ããã¯ãã¾ããªã(å人çã«ã¯å¥½ãã§ã¯ç¡ãã§ãã)ãRequest-Dispath-Process-Templateãã¿ã¼ã³ã¨ãããããªååã«ããã°ããã£ããã ã¨æãã¾ããããã¾ããã£ããã¼ãªååãããªããã使ã人ãå°ãªãã£ãããç¥ãã¾ãããã
*1:ããã¯æ¶ç©ºã®ã©ã¤ãã©ãªãæ³å®ãã¦ãã¾ã