1. MVC
关于
MVC
的介绍和使用
M
:Model
模型V
:View
视图C
:Controller
控制器
传统MVC
模式
View
接收用户的交互请求View
将请求转交给Controller
Controller
完成业务逻辑后,对Model
进行数据更新Model
将新的数据发送到View
View
显示新的数据,用户得到反馈
不完整的MVC
模式
- 用户直接请求
Controller
Controller
操作访问Model
,对Model
进行更新Controller
将Model
中更新的数据转送到View
View
对数据进行渲染
MVC
的特点
MVC
模式间的通信都是单向的。View
和Controller
使用Strategy
(策略)模式实现,View
使用Composite
(组合)模式,View
和Model
使用Observer
(观察者)模式。Controller
对View
的细节不可见,一个Controller
可被多个View
对用。MVC
的一个缺点是难以对Controller
进行单元测试