What are the differences between MVC, MVP and MVVM

2020-02-04 02:08发布

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.

MVVM seems a little different in that the controller seems to be more of a part of the framework, such as with XAML bindings.

What is the "Cliff's Notes" explanation of the differences?

1条回答
仙女界的扛把子
2楼-- · 2020-02-04 02:47

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.

查看更多
登录 后发表回答