MVC vs MVP vs MVVM

本文详细介绍了三种常见的软件架构模式:MVC、MVP和MVVM。MVC将应用数据管理、视图呈现和用户交互分离;MVP则进一步强化了模型和视图的分离,将视图逻辑移到了Presenter中;而MVVM通过双向数据绑定简化了视图和模型的状态同步。每种模式各有侧重,适合不同的应用场景。
摘要由CSDN通过智能技术生成

MVC vs MVP vs MVVM

MVC

MVC是最早也是最为人所知道的分层架构模式,主要的层级特点是:

  1. The model is responsible for managing the data of the application. It receives user input from the controller.
  2. The view renders presentation of the model in a particular format.
  3. The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.
MVP

MVP是MVC上发展出来的模式,主要的层级特点是:

  1. The model is an interface defining the data to be displayed or otherwise acted upon in the user interface.
  2. The view is a passive interface that displays data (the model) and routes user commands (events) to the presenter to act upon that data.
  3. The presenter acts upon the model and the view. It retrieves data from repositories (the model), and formats it for display in the view.

在这里插入图片描述

我理解它与MVC不同的主要是关注点不同,MVP的展现逻辑更重,所以不再单独由View来控制,而是将视图逻辑放在了Presenter。这种模式更偏向后台View逻辑。

MVVM(Model–view–viewmodel)

MVVM是最近几年才出来的,主要的层级特点是:

  1. Model refers either to a domain model, which represents real state content (an object-oriented approach), or to the data access layer, which represents content (a data-centric approach)

  2. View As in the model–view–controller (MVC) and model–view–presenter (MVP) patterns, the view is the structure, layout, and appearance of what a user sees on the screen.[7] It displays a representation of the model and receives the user’s interaction with the view (mouse clicks, keyboard input, screen tap gestures, etc.), and it forwards the handling of these to the view model via the data binding (properties, event callbacks, etc.) that is defined to link the view and view model.

  3. View model The view model is an abstraction of the view exposing public properties and commands. Instead of the controller of the MVC pattern, or the presenter of the MVP pattern, MVVM has a binder, which automates communication between the view and its bound properties in the view model. The view model has been described as a state of the data in the model.[8]

    The main difference between the view model and the Presenter in the MVP pattern is that the presenter has a reference to a view, whereas the view model does not. Instead, a view directly binds to properties on the view model to send and receive updates. To function efficiently, this requires a binding technology or generating boilerplate code to do the binding

在这里插入图片描述

主要是对视图层增加双向绑定,从而可以有效的简化View和Model之间的状态同步。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值