Skip to content

MVC、MVP、MVVM

Hannah0103 edited this page Dec 22, 2025 · 1 revision

架构对比

MVC:三角混## 乱

  View
   ↑↓

Controller ←→ Model 👉 View 和 Controller 双向强依赖

MVP:单向依赖

View ←---→ Presenter ←→ Model 协议 👉 View 是接口(protocol),Presenter 不知道具体是谁

真正的 MVP 必须做到: ✅ View 是一个协议(Protocol) ✅ Presenter 只持有 id,不知道具体是哪个 ViewController ✅ 所有 UI 更新都通过协议方法通知

MVVM 对比版本(用 Combine 实现绑定)

特性 | Swift + Combine | Objective-C 替代方案 🔄 数据绑定 | @Published + @ObservedObject | KVO、NSNotification、手动回调 🧠 响应式编程 | Combine / async/await | ReactiveObjC(RAC) 或 手动封装 🔁 双向绑定 | @Binding | 手动监听 TextField 事件 + KVO

View (LoginViewController) ↑↓ 通过 KVO / 代理 / Block 监听 ViewModel (LoginViewModel) ↓ Model (UserService)

Clone this wiki locally