ã€ã³ã¿ãŒãããã§ã¯ãå€ãã®ç°ãªãå®è£
ãšã¹ããŒã ããã§ã«ã»ã€ããMVCãã¿ãŒã³ãèŠã€ããããšãã§ããŸãã ããŸããŸãªæ¬ã§ãããŸããŸãªã¹ããŒã ã«ãåºäŒã£ãã ããã«ããã以åã®èšäºã
PHPã§ååºãµã€ããäœæããäŸã䜿çšããŠMVCãã¿ãŒã³ãå®è£
ãã ãã«å¯Ÿããæ··ä¹±ãšã³ã¡ã³ããçºçããŸãã çå®ãæ±ããŠãç§ã¯ãã¹ãŠããã®å Žæã«çœ®ãããšããŸãã...ç§ã¯ãã¶ã€ã³ãã¿ãŒã³ã«é¢ããããã€ãã®æç®ãšèšäºãèªã¿ãèšåãããèšäºã«è£éºãæžããŸããã ãããããã£ãŒãããã¯ãæåŸ
ããŠå¥ã®ãããã¯ãšããŠããã®ã¢ããªã³ãæçš¿ããããšã«ããŸããã
ã«ããã®äžã«ã¯ãäžè¬çãªMVCããã³MVPã¹ããŒã ããããã¢ããªã±ãŒã·ã§ã³ã®ã©ã€ããµã€ã¯ã«ã®èª¬æãšãããŸã人æ°ã®ãªãHMVCããã³MVVMãã¿ãŒã³ã®èª¬æããããŸãã ãã¡ããããããã®ãã¿ãŒã³ã®äžéšã¯Webã¢ããªã±ãŒã·ã§ã³ã ãã§ãªããèšäºã§ã¯ãã®æèã§èæ
®ãããŠããŸãã
MVC
MVCãã³ãã¬ãŒãïŒModel-View-ControllerãŸãã¯Model-State-BehaviorïŒã¯ãããžãã¹ããžãã¯ããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ããåé¢ããããšãç®çãšãããã¢ããªã±ãŒã·ã§ã³æ§é ãæ§ç¯ããç°¡åãªæ¹æ³ã説æããŠããŸãã ãã®çµæãã¢ããªã±ãŒã·ã§ã³ã®ã¹ã±ãŒãªã³ã°ããã¹ããä¿å®ã容æã«ãªãããã¡ããå®è£
ãããŸãã
MVCã«é¢ããããã€ãã®çµè«ã¢ãã« -ã¢ããªã±ãŒã·ã§ã³ã®ããžãã¹ããžãã¯ãå«ãŸããŠããããµã³ããªã³ã°ã¡ãœããïŒãããã¯ORMã¡ãœããã®å ŽåããããŸãïŒãåŠçïŒæ€èšŒã«ãŒã«ãªã©ïŒãããã³ç¹å®ã®ããŒã¿ã®æäŸãå«ã¿ãŸãã
ã¢ãã«ã¯ãŠãŒã¶ãŒãšçŽæ¥å¯Ÿè©±ããªãã§ãã ããã ãŠãŒã¶ãŒèŠæ±ã«é¢é£ãããã¹ãŠã®å€æ°ã¯ãã³ã³ãããŒã©ãŒã§åŠçããå¿
èŠããããŸãã
ãã®ã¢ãã«ã§ã¯ããŠãŒã¶ãŒã®ããŒãºã«å¿ããŠç°ãªãå¯èœæ§ã®ããHTMLãŸãã¯ãã®ä»ã®è¡šç€ºã³ãŒããçæããªãã§ãã ããã ãã®ãããªã³ãŒãã¯ãã¥ãŒã§åŠçããå¿
èŠããããŸãã
åäžã®ã¢ãã«ãããšãã°ããŠãŒã¶ãŒèªèšŒã¢ãã«ã¯ããŠãŒã¶ãŒãšã¢ããªã±ãŒã·ã§ã³ã®ç®¡çéšåã®äž¡æ¹ã§äœ¿çšã§ããŸãã ãã®å Žåãç¶æ¿è
ã§ã¢ããªã±ãŒã·ã§ã³åºæã®ã¡ãœãããå®çŸ©ããããšã«ãããäžè¬çãªã³ãŒããå¥ã®ã¯ã©ã¹ã«åã蟌ã¿ãããããç¶æ¿ã§ããŸãã
ãã¥ãŒ -ã³ã³ãããŒã©ãŒãšã¢ãã«ããåä¿¡ããããŒã¿ã®å€éšè¡šç€ºãæå®ããããã«äœ¿çšãããŸãã
ãã¥ãŒã«ã¯ãããŒã¿ãã¯ããŒã«ããã©ãŒããããããã³è¡šç€ºããããã®HTMLããŒã¯ã¢ãããšå°ããªPHPã³ãŒãã®æ¿å
¥ãå«ãŸããŸãã
ããŒã¿ããŒã¹ã«çŽæ¥ã¢ã¯ã»ã¹ããªãã§ãã ããã ããã¯ã¢ãã«ã«ãã£ãŠè¡ãããã¹ãã§ãã
ãŠãŒã¶ãŒã®ãªã¯ãšã¹ãããååŸããããŒã¿ãåŠçããªãã§ãã ããã ãã®ã¿ã¹ã¯ã¯ã³ã³ãããŒã©ãŒãå®è¡ããå¿
èŠããããŸãã
ã³ã³ãããŒã©ãŸãã¯ã¢ãã«ã®ããããã£ãšã¡ãœããã«çŽæ¥ã¢ã¯ã»ã¹ããŠãåºåå¯èœãªããŒã¿ãååŸã§ããŸãã
ãã¥ãŒã¯éåžžããã¹ãŠã®ããŒãžïŒããããŒãããã¿ãŒãªã©ïŒã«å
±éã®ããŒã¯ã¢ãããå«ãå
±éãã³ãã¬ãŒããšãã¢ãã«ããã®ããŒã¿åºåã®è¡šç€ºãŸãã¯ããŒã¿å
¥åãã©ãŒã ã®è¡šç€ºã«äœ¿çšããããã³ãã¬ãŒãã®éšåã«åå²ãããŸãã
ã³ã³ãããŒã©ãŒã¯ãã¢ãã«ããã¥ãŒããã®ä»ã®ã³ã³ããŒãã³ããåäœäžã®ã¢ããªã±ãŒã·ã§ã³ã«æ¥ç¶ããæ¥ç¶ãªã³ã¯ã§ãã ã³ã³ãããŒã©ãŒã¯ããŠãŒã¶ãŒã®ãªã¯ãšã¹ããåŠçããŸãã ã³ã³ãããŒã©ã«SQLã¯ãšãªãå«ããããšã¯ã§ããŸããã ãããã¯ã¢ãã«ã«ä¿åããã®ãæé©ã§ãã ã³ã³ãããŒã©ãŒã«HTMLãŸãã¯ãã®ä»ã®ããŒã¯ã¢ãããå«ããããšã¯ã§ããŸããã ããã¯çš®ã«å
¥ããããã¹ãã§ãã
é©åã«èšèšãããMVCã¢ããªã±ãŒã·ã§ã³ã§ã¯ãã³ã³ãããŒã©ãŒã¯éåžžéåžžã«èããæ°åè¡ã®ã³ãŒãããå«ãŸããŠããŸããã Joomla CMSã®Stupid Fat ControllerïŒSFCïŒã«ã€ããŠãåãããšã¯èšããŸããã ã³ã³ãããŒã©ãŒã®ããžãã¯ã¯éåžžã«å
žåçã§ããããã®ã»ãšãã©ã¯åºæ¬ã¯ã©ã¹ã§å®è¡ãããŸãã
ããã©ããããã¢ãã«ã¯éåžžã«åããããŒã¿åŠçã«é¢é£ããã»ãšãã©ã®ã³ãŒããå«ãŸããŠããŸãã ãããã«å«ãŸããããŒã¿æ§é ãšããžãã¹ããžãã¯ã¯ãéåžžãç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ã«éåžžã«åºæã®ãã®ã§ãã
ã€ã³ã¿ãŒãããäžã®ãMVCãã®ãªã¯ãšã¹ãã§ãå€ãã®ç°ãªãã¹ããŒã ãèŠã€ããããšãã§ããŸãã ãã¹ãŠãé©åãªå Žæã«é
眮ããŠã¿ãŸãããã ã¹ããŒã 1ãæ€èšããŠãã ããïŒ
1.ãŠãŒã¶ãŒãWebãªãœãŒã¹ãå
¥åãããšãåæåã¹ã¯ãªãããã¢ããªã±ãŒã·ã§ã³ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããå®è¡ã®ããã«èµ·åããŸãã
2.ããã³ãã³ã³ãããŒã©ãŒã®ã€ã³ããã¯ã¹ã¢ã¯ã·ã§ã³ãå®è¡ãããã¡ã€ã³ããŒãžã®ãã¥ãŒãçæãããŸãã
3.ãã¥ãŒããŠãŒã¶ãŒã«è¡šç€ºãããŸãã
æåã®3ã€ã®ã¹ãããã¯ãã¢ãã«ã䜿çšããªãåçŽãªãã§ãŒã³ã§ãã 次ã¯ãã¢ãã«ãé¢äžããã·ãŒã±ã³ã¹ã§ãã
4.ã¢ããªã±ãŒã·ã§ã³ããŠãŒã¶ãŒãããªã¯ãšã¹ããåä¿¡ãããšããªã¯ãšã¹ããããã³ã³ãããŒã©ãŒã®ã€ã³ã¹ã¿ã³ã¹ãäœæãããæå®ãããã¢ã¯ã·ã§ã³ãåŒã³åºãããŸãã
5.ãã®ã¢ã¯ã·ã§ã³ã§ã¯ããããå€æŽããã¢ãã«ã®ã¡ãœãããåŒã³åºãããŸãã
6.ãã¥ãŒãçæãããŸãïŒãŸãã¯ããã¥ãŒã«ã¢ãã«ã®æŽæ°ãéç¥ãããŸãïŒã
7.ãã¥ãŒã¯è¡šç€ºçšã®ããŒã¿ãèŠæ±ããŸãã
8.ã¢ãã«ã¯èŠæ±ãããããŒã¿ãè¿ããŸãã
9.ãã¥ãŒã¯çµæããŠãŒã¶ãŒã«è¡šç€ºããŸãã
ãã®ãããªã¹ããŒã ããããŸã-ã¹ããŒã 2ïŒ
1.ã³ã³ãããŒã©ãŒã¯ãŠãŒã¶ãŒãã次ã®ãªã¯ãšã¹ããåãåããŸãã
2.ããã«ãå
éšããžãã¯ã«å¿ããŠïŒ
2aã ããŒãžã®ãã¬ãŒã³ããŒã·ã§ã³ã圢æãããŸãã
2bã ãŸãã¯ãã¢ãã«ã®ã¡ãœãããåŒã³åºãããŸãã
3.ã¢ãã«ã¯ãå€æŽã®ãã¥ãŒã«éç¥ããŸãã
4.ãã¥ãŒãæŽæ°ããïŒã¢ãã«ããã§ãŒã³ã«å«ãŸããŠããå ŽåïŒããŠãŒã¶ãŒã«è¡šç€ºãããŸãã
äžéšã®å³ã§ã¯ããã¥ãŒããã³ã³ãããŒã©ãŒãžã®ç¢å°ãèŠãããšãã§ããŸãã ãã®ã±ãŒã¹ãèæ
®ããŠãã ãã-ã¹ããŒã 3ïŒ
- ã¢ããªã±ãŒã·ã§ã³ã¯ããŠãŒã¶ãŒããå¥ã®èŠæ±ãåãåããŸããèŠæ±ãããã³ã³ãããŒã©ãŒã®ã€ã³ã¹ã¿ã³ã¹ãäœæããæå®ãããã¢ã¯ã·ã§ã³ãåŒã³åºããŸãã
- å®éã«ã¯ãäœããã®åœ¢åŒã®ããŒã¿å
¥åãå«ããã¥ãŒãçæãããŸãã
- ãã©ãŒã ãå«ããã¥ãŒããŠãŒã¶ãŒã«è¡šç€ºãããŸãã
- ãŠãŒã¶ãŒããã©ãŒã ã«å
¥åããŠãéä¿¡ããã¿ã³ãã¯ãªãã¯ãããšãåãã³ã³ãããŒã©ãŒãåŒã³åºããããã©ãŒã ããåä¿¡ããããŒã¿ããã§ãã¯ããŠåŠçããå¥ã®ãã¥ãŒãäœæããããçŸåšã®ãã¥ãŒãæŽæ°ããŸãã
å®éãã¹ããã4ã¯ãæ°ãããµã€ã¯ã«ãåæåããå¥ã®ã¹ããã1ãšåçã§ãããããã£ãŠããã¹ãŠã®ã¹ããŒã ã§ããã¥ãŒããã³ã³ãããŒã©ãŒãžã®æ¹åã®æé»çãªæ¥ç¶ãæ³å®ã§ããŸãã
MVP
次ã«ã
MVP ïŒModel-View-PresenterïŒãã¿ãŒã³å³ãèŠãŠãã ãã-å³4ïŒ
- ã¢ããªã±ãŒã·ã§ã³ããŠãŒã¶ãŒãããªã¯ãšã¹ããåä¿¡ãããšããªã¯ãšã¹ãããããã¬ãŒã³ã¿ãŒãšã¢ã¯ã·ã§ã³ã決å®ãããŸãã ã¢ããªã±ãŒã·ã§ã³ã¯ãã®ãã¬ãŒã³ã¿ãŒã®ã€ã³ã¹ã¿ã³ã¹ãäœæããã¢ã¯ã·ã§ã³ã¡ãœãããèµ·åããŸãã
- ã¢ã¯ã·ã§ã³ã¡ãœããã«ã¯ãããŒã¿ããŒã¹ããã®æ
å ±ã®èªã¿åããªã©ãã¢ãã«ã®åŒã³åºããå«ãŸããå ŽåããããŸãã
- ã¢ãã«ã¯ããŒã¿ãè¿ããŸãã
- ãã®åŸãã¢ã¯ã·ã§ã³ã¯ãã¢ãã«ããååŸããããŒã¿ãéä¿¡ããããã¥ãŒã圢æããŸãã
- çæããããã¥ãŒããŠãŒã¶ãŒã«è¡šç€ºãããŸãã
MVPã«å ããŠã
MVVMã
HMVCãªã©ãMVCãã掟çããä»ã®ãã¿ãŒã³ããã
ãŸã ã
Hmvc
HMVC ïŒHierarchical Model View ControllerïŒãã¿ãŒã³ã®å®è£
ã¯ã
Kohana Webãã¬ãŒã ã¯ãŒã¯ã§äœ¿çšãããŸãã MVCãšã®äž»ãªéããèæ
®ããŠãã ãã-ã¹ããŒã 5ïŒ
ã¢ããªã±ãŒã·ã§ã³ã¯ãç¬ç«ããMVCãã©ã€ã¢ãã®éå±€ã瀺ããŸãã åæã«ãåãã©ã€ã¢ãã¯ä»ã®ãã©ã€ã¢ãã®ã³ã³ãããŒã©ãŒã«çŽæ¥æ¥ç¶ã§ããŸãã ãã®ã¢ãããŒãã«ãããåŸæ¥ã®MVCã¢ãŒããã¯ãã£ã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ã®ã¹ã±ãŒã©ããªãã£ã®åé¡ã解決ããã¢ããªã±ãŒã·ã§ã³ã®ããŸããŸãªéšåéã®äŸåé¢ä¿ãæžãããã³ãŒãã®ãããªããµããŒããšåå©çšãä¿é²ã§ããŸãã ãã®ã¢ãããŒãã®å©ç¹ã«ã€ããŠã¯ãèšäºã
HMVCã䜿çšããWebã¢ããªã±ãŒã·ã§ã³ã®ã¹ã±ãŒãªã³ã° ããåç
§ããŠãã ããã
MVVM
MVCã¯ããªã¯ãšã¹ã/ã¬ã¹ãã³ã¹ã¹ã¯ãªãããéåžžã«ããŸãåŠçãããããäž»ã«Webã¢ããªã±ãŒã·ã§ã³ã«å®çããŸããã
ãã®ã·ããªãªã®äž»ãªæ©èœã¯ããã¥ãŒã®å¯¿åœãçãããšã§ãã èŠæ±ãå°çãããšãé©åãªã³ã³ãããŒã©ãŒã«éä¿¡ãããã¢ãã«å
ã®ããã€ãã®ããã»ã¹ãéå§ãããŸãã次ã«ãã¢ãã«ããã®ããŒã¿ã§æºãããããã©ãŠã¶ãŒã§ã¯ã©ã€ã¢ã³ãã«éä¿¡ããããã¥ãŒãäœæãããŸãã 1åã®å®è¡ã§ãã¹ãŠã
Ajaxãšãªããã¯ã©ã€ã¢ã³ããµã€ãã¢ããªã±ãŒã·ã§ã³ïŒ
RIA ïŒãç»å ŽãããšããMVCã¯ããŒãžãŸãã¯ã¢ããªã±ãŒã·ã§ã³é åã§ã®äœæ¥ã«ã¯ããŸãé©ããŠããªãããšãå€æããŸãããããã«ãããMVPïŒã¢ãã«ãã¥ãŒãã¬ãŒã³ã¿ãŒïŒãšMVVMïŒã¢ãã«ãã¥ãŒViewModel ïŒ MVCããã³MVPãã¿ãŒã³ã«ã»ãšãã©ç²ŸéããŠãã人ã¯ã»ãšãã©ããŸãããåŸè
ã«ã€ããŠèãã人ã¯ã»ãšãã©ããŸããã
MVVMã¯å
ã
Silverlightåãã«èšè¿°ããããã®ã§ãã¢ããªã±ãŒã·ã§ã³ããžãã¯ãšã¯ç°ãªãç¹å®ã®ããžãã¯ãæã€è€éãªã€ã³ã¿ãŒãã§ã€ã¹ã«å¯ŸããŠå©ç¹ããããŸãã MVVMã®ç¹åŸŽã¯ãView-Modelã¬ã€ã€ãŒãä»ããã¢ãã«ãšãã¥ãŒã®ããç·å¯ãªé¢ä¿ã§ããããã«ãããã¢ãã«åŽãšãã¥ãŒåŽã®äž¡æ¹ã®ã€ãã³ãã§ããŒã¿ãåæãããŸãã
MVCã§ã¯ãããžãã¯ã¯ã¢ãã«ã«é
ç·ãããã³ã³ãããŒã©ãŒã«é
眮ããããšãã§ããŸãããããã¯æ£ããæ¹å€ãããŠããŸãïŒæããªèèªã³ã³ãããŒã©ãŒïŒã 察ç
§çã«ãMVVMã§ã¯ãããžãã¯ã¯ViewModelã®ãäžéãã¬ã€ã€ãŒã«é
眮ãããŸãã MVVMã¹ããŒã ãæ€èšããŠãã ãã-ã¹ããŒã 6ïŒ
å®è¡æã«è¡šç€ºãããã³ã³ãã³ããç¥ããã«ãç»é¢ã®è¡šç€ºé åã決å®ããç»é¢ã«é¢ããæãäžè¬çãªããŒã¿ãèšå®ããŸãã HTMLã®å ŽåãMVVMã¹ããŒã ã¯
DOMã®ãããã§ç¹ã«æåããŠããŸãããåç¥ã®ããã«ã
DOMã«ã¯ããŒã¿ãå«ãŸããŠããå¯èœæ§ããããŸãã ãããã£ãŠãMVVMã¯
KnockOut.JSãã¬ãŒã ã¯ãŒã¯ã«æ£åžžã«å®è£
ãããŸããã æåã¯ããã¹ãŠãç°¡åã§ãã ãµãŒããŒã«ãã£ãŠæäŸãããããŒã¿ã¢ãã«ããããŸãã DOMã®åœ¢åŒã§ãããŒã¯ã¢ããã®åœ¢åŒã§è¡šçŸããããŸãã ãŸãããã¥ãŒã®å€æŽãèšè¿°ããã¢ãã«ãšãã¥ãŒãæ¥ç¶ãããã®é¢ä¿ãåæãããã¥ãŒã¢ãã«ïŒå¿
èŠã«å¿ããŠã¢ãã«ã®ãã¥ãŒïŒããããŸãã
MVCã¯å€ãã®å Žåãã¢ããªã±ãŒã·ã§ã³ã®3ã€ã®ã¬ãã«ã®åé¢ãšããŠåã«è§£éããããããã®éã®é¢ä¿ãèŠå¶ããªãããšã«æ³šæããŠãã ããã ãã®ãããå€ãã®å Žåãã¢ãã«ãšãã¥ãŒãç¢å°ã§æ¥ç¶ãããŠãããã€ã¢ã°ã©ã ïŒäžèšã®1ã€ããããŸãïŒããããŸããããã®æ¹æ³ã§ã¯ãç°ãªããã¥ãŒãšã³ã³ãããŒã©ãŒã®éå±€ã䜿çšãããšãã«æçšãªã¹ã±ãŒã©ããªãã£ããããã£ã倱ãããããšã¯æããã§ãã
ãããã«
èšåããããã¿ãŒã³ã®ã©ããåªããŠããããªã©ã®è³ªåã«çããå¿
èŠã¯ãããŸãã...äž»ãªã¢ã€ãã¢-ãåå²ããŠåŸæãããã ããäœæããå¿
èŠããããŸããã¬ã€ã€ãŒãç¬ç«ããŠãããç°¡åã«äº€æã§ããããšãéåžžã«éèŠã§ãã
䟿å©ãªãªã³ã¯é䟿å©ãªãªã³ã¯
ã¯ã©ã€ã¢ã³ãåŽã®ã¢ããªã±ãŒã·ã§ã³ã«é¢é£ããMVVMãMVPãMVCã«ã€ããŠããå°ã詳ãã...
ãã®ä»ã®ãã¿ââãŒã³ïŒ
IoCããã³
DIAOPãã®ãã¿ãã¬ã®äžã®éžæã¯äž»é¡ã§ã¯ãããŸãã...ç§ã¯èªåã®ããã«ããããã£ãšäœããŸããã èšäºã®å·çäžããŠã§ããµãŒãã£ã³ã¯ãããã®ãªã³ã¯ã«çŠç¹ãåãããŠããŸããã