MVC、MVP、MVVM
2020-04-08 本文已影响0人
醉卧梦星河
MVC、MVP、MVVM
mvc
,mvp
,mvvm
架构的演进是为了解耦业务,其中这三个部分都是业务逻辑处理这部分变化,且改变处理业务逻辑和另外两个模块的关联。C
->P
->VM
。

- 视图
View
:用户界面 - 控制器
Controller
:业务逻辑 - 模型
Model
: 数据保存
MVC

-
View
接收到指令传给Controller
-
Controller
完成逻辑任务后改变Model
-
Model
将新的数据发到View
,反馈给用户。
所有的通讯都是单向的。
MVP

- 双向传递。
-
View
与Model
不发生关联,而是通过Presenter
传递。 -
Presenter
承担了所有的业务逻辑
MVVM
MVVM
模式将 Presenter
改名为 ViewModel
,基本上与 MVP
模式完全一致。

唯一的区别是,它采用双向绑定(
data-binding
):View
的变动,自动反映在 ViewModel
,反之亦然。