ãæè¡ãMVVMã«ãªãããªãã£ãçç±ãèãã¦ã¿ã
åãã«
ã¢ããªã®æ§é ãèããã¨ãã«ãMVCãMVVMãã©ã¡ãã«ãããæ©ããã¨ãããã¨æãã¾ããç§ã¯ããã¾ã§Javaã®SpringBootã®æ¥åã¢ããªã°ããä½ã£ã¦ãã¾ããã®ã§ãMVCã«ã¯ãªãã¿ãããç解ãã¦ããã¤ããã§ãããMVVMã¯å®åã§è§¦ã£ããã¨ããªãããã¾ããªãããã«ãã¾ããã
ãã ãæè¿ããã³ãã¨ã³ãéçºã«ãé¢ããã ããReactã触ãæ©ä¼ãããã¾ããããã®ä¸ã§ãªãMVVMãããããã£ã¦ããªãã£ãã®ãã¤ãããã®ã§ãå¿ããªããã¡ã«ã¾ã¨ãã¦ãããã¨æãã¾ããåããããªãã¨ã§æ©ã¾ãã¦ããæ¹ã®åèã«ããã°å¹¸ãã§ãã
MVCã¨ã¯
MVCã¨ã¯ãModel/View/Controllerã®3è¦ç´ ã§æãç«ã¤ã¢ã¼ããã¯ãã£ã§ããModelã¯ãã¸ãã¹ãã¸ãã¯ããViewã¯ç»é¢è¡¨ç¤ºããControllerã¯Modelã¨Viewã®ä»²ä»å½¹ãåãã¾ãã
MVVMã¨ã¯
MVVMã¨ã¯ãModel/View/ViewModelã®3è¦ç´ ã§æãç«ã¤ã¢ã¼ããã¯ãã£ã§ããModelãViewã¯MVCã¨åããControllerã«ãããã®ãViewModelã«ãªãã¾ãã¾ããViewModelã®ãã¼ã«ãªãèãæ¹ããã¼ã¿ãã¤ã³ãã£ã³ã°ã§ãViewã¾ãã¯Modelã®ã©ã¡ããã§ãã¼ã¿ã®å¤æ´ãçºçããå ´åã«ãç¸äºã«View/Modelã§ãã¼ã¿ã®æ´æ°ãçºçãã¾ãã
ãªããªãããªãã£ãã
ç§ã¯åæé信主ä½ã®ã¢ããªããä½ã£ããã¨ããªãã£ãã®ã§ãAjaxéä¿¡ã使ãã®ã¯æ¤ç´¢ãããã¢ããç»é¢ãä½ãæããããã¨ããç¶æ ã§ããããªã®ã§ããViewã§ã®å¤æ´ã¨Modelã§ã®å¤æ´ãç¸äºã«åæ ãããã¨ããããã¼ã¿ãã¤ã³ãã£ã³ã°ãã®èãæ¹ãç解ã§ããã«ãã¾ããããã ãReactãªã©ã®å®£è¨çãªUIãåæã¨ããFWã触ããPropsãStateã¨ãã£ãæ¦å¿µãææ¡ãããã¨ã§ããã¼ã¿ãã¤ã³ãã£ã³ã°ã®èãæ¹ãç解ã§ãã¾ããã
PropsãStateã¨ããã®ã¯Reactã«ããã¦å é¨çã«è¡¨ç¤ºãããã¼ã¿ã管çããæ¹æ³ã®ãã¨ã§ããããããå®ç¾©ãããã¼ã¿æ´æ°ç¨ã®é¢æ°ã使ããã¨ã§ãViewã®æ´æ°ãModelå´ã«åæ ããã¨ããèãæ¹ããã¦ãã¾ããç§ã¯ç¡æèã«åæéä¿¡ãåæã«å¦çãèãã¦ããã®ã§ãViewModelãControllerã®ä»£æ¿ã¨ããæãããã©ãéãã®ãï¼ãããããã«ããã®ã§ãã
ã§ã¯ãªãæè¿ã«ãªã£ã¦è ¹è½ã¡ãããã¨ããã¨ãæè¿Typescriptã触ãæ©ä¼ããããéåæéä¿¡ãåæã¨ããè¨è¿°ã«ãªãããã¨ãã§ãã¾ããããã®ä¸ã§ãéåæéä¿¡ã¨ãã¦å¦çãããã¨ãããã¨ã¯ãViewããéä¿¡ãããæ å ±ãModelã«æ¸¡ããModelãã帰ã£ã¦ããæ å ±ãViewã«æ¸¡ããã¨ããæµããä¸çµã§å®è£ ããªãã¦ããã¨ç解ã§ããã®ã§ãï¼éåæéä¿¡ãªã®ã§å½ããåãªã®ã§ããï¼ã
MVCã¨MVVMã®æ±ºå®çãªéã
MVCã¨MVVMã¯ãåæéä¿¡ã«ãªããã®ããéåæéä¿¡ã«ãªããã®ããã¨ããèãæ¹ã®éããããã®ã§ã¯ãªããã¨æãã¾ããã¤ã¾ããéä¿¡ã®èãæ¹ãä¸æ¹éè¡ãªã®ããåæ¹åãªã®ãã¨ãããã¨ã§ãã
- MVCã®å ´å : éä¿¡ã¯ãV->C->M->C->Vã§ç»é¢ããç»é¢ã¾ã§ã®éä¿¡ãä¸çµã§å®è£ ããããï¼C->M->Cã®é¨åã¯ä¸å¯¾ä¸å¯¾å¿ããå¼ã³åºãå ã®Cã¨ãã¼ã¿ãè¿ãéã®Cã®ã¡ã½ããã¯ä¸ç·ã«ãªããï¼
- MVVMã®å ´å : éä¿¡ã¯ãV->VM->Mã¨ãM->VM->Vã®äºçµã«åå²ããã¦å®è£ ããããï¼VM->Mã¨M->VMã®VMé¨åã¯ç°ãªãã¡ã½ããã§å®ç¾ãããCallbackã«å¾è ãæå®ãããã¨ã§çµã³ä»ãããããï¼
ä¸è¨ã®å·®ã«ãã£ã¦ãMVCã®å ´åã¯Vãå¿ ãå¦çã®èµ·ç¹ã«ãªãã¾ãï¼ä¸æ¹éè¡ï¼ããMVVMã®å ´åã¯VããVMããMããVMãå¼ã³åºãå¦çãããããå®è£ ãããã®ã§ãVã¨Mãããããèµ·ç¹ã®å¦çã«ãªãï¼åæ¹åï¼ã®ã§ãï¼ã¤ã¾ãããããã¼ã¿ãã¤ã³ãã£ã³ã°ã®èãæ¹ã®ãã¼ãªã®ã§ãï¼ããããè ¹è½ã¡ããæç¹ã§ãã£ã¨ãã¼ã¿ãã¤ã³ãã£ã³ã°ã¨ããèãæ¹ã表層çãªæå³ä»¥ä¸ã«ç解ã§ããæ°ããã¾ãã
çµããã«
ä»åã¯MVVMã¨MVCã¢ã¼ããã¯ãã£ã®éãã«ã¤ãã¦ãèªåãªãã«ç解ããå 容ãã¾ã¨ãã¦ã¿ã¾ãããããã¾ã§å人ã®è¦è§£ã®ãããééã£ã¦ããç¹ãããã°ã容赦ãã ããã