What are the differences between MVC, MVP and MVVM?

后端 未结 1 816
灰色年华
灰色年华 2020-12-09 04:27

From what I can gather, the first two don\'t seem that different. Whether it\'s called a controller or presenter, it still seems to have the same mediation functions.

<
相关标签:
1条回答
  • 2020-12-09 05:27

    The difference is in way how data from model layer ends up in the view instances.

    • in classical MVC (and also in Model2 MVC) view is active structure. It requests information from model layer. Controller only changes the state of model layer and view.
    • in MVP the view is passive. Instead presenter request information from model layer and passes it the view. You can read more extensively on about MVP pattern here.
    • in MVVM is similar to MVP, but the viewmodel has to manipulate the information before passing it to view.

    The difference between MVP and MVVM is in the development process. You would use MVP pattern, when creating presentation layer for a known model layer.

    But you will have to use MVVM, if you have a preexisting (or for some reason - un changeable) user interface and preexisting (or unchangeable) model layer. And you have to make them work together. That's where viewmodel comes into play.

    0 讨论(0)
提交回复
热议问题