MVC、MVP 和 MVC 之间有什么区别?MVVM 设计模式在编码 c# 方面 [英] What is difference between MVC, MVP & MVVM design pattern in terms of coding c#

查看:20
本文介绍了MVC、MVP 和 MVC 之间有什么区别?MVVM 设计模式在编码 c# 方面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们使用短语MVC, MVP & 之间的差异"来搜索 GoogleMVVM 设计模式"那么我们可能会得到一些讨论 MVC MVP & 之间的区别MVVM 设计模式理论上像:

If we search Google using the phrase "differences between MVC, MVP & MVVM design pattern" then we may get a few URL's which discuss the difference between MVC MVP & MVVM design pattern theoretically like:

MVP

在通过dataContext"绑定的情况下使用不可能.Windows 窗体就是一个很好的例子.为了将视图与模型分开,需要一个演示者.由于视图不能直接绑定到presenter,信息必须通过接口(IView)传递给视图.

Use in situations where binding via a "dataContext" is not possible. Windows Forms is a perfect example of this. In order to separate the view from the model, a presenter is needed. Since the view cannot directly bind to the presenter, information must be passed to the view via an interface (IView).

MVVM

在通过dataContext"绑定的情况下使用是可能的.为什么?删除了每个视图的各种 IView 接口,这意味着需要维护的代码更少.MVVM 可以使用 Knockout 包含 WPF 和 javascript 项目的一些示例.

Use in situations where binding via a "dataContext" is possible. Why? The various IView interfaces for each view are removed which means less code to maintain. Some examples where MVVM is possible to include WPF and javascript projects using Knockout.

MVC

在视图和程序其余部分之间的连接并不总是可用的情况下使用(并且您不能有效地使用 MVVM 或 MVP).这清楚地描述了 Web API 与发送到客户端浏览器的数据分离的情况.Microsoft 的 ASP.NET MVC 是管理此类情况的绝佳工具,并提供了非常清晰的 MVC 框架

Use in situations where the connection between the view and the rest of the program is not always available (and you can’t effectively employ MVVM or MVP). This clearly describes the situation where a web API is separated from the data sent to the client browsers. Microsoft’s ASP.NET MVC is a great tool for managing such situations and provides a very clear MVC framework

但我还没有找到一篇文章从理论上讨论差异以及示例代码.

But I have not found a single article which discusses the difference theoretically along with sample code.

如果我能有一篇文章讨论这 3 种设计模式(MVC、MVP 和 MVVM)之间的区别以及代码,那就太好了.

It would be really nice if I get an article that discusses the difference between these 3 design patterns (MVC, MVP & MVVM) along with code.

我想了解 3 个类似的 CRUD 应用程序的源代码,这些应用程序已通过这三种设计模式(MVC、MVP 和 MVVM)实现.这样我就可以通过代码了解应该如何为这三种设计模式(MVC、MVP 和 MVVM)编写代码.

I'd like to get my hands on the source code of 3 similar CRUD apps that have been implemented by these three design patterns (MVC, MVP & MVVM). So that I can go through the code and understand how one should write code for these three design pattern (MVC, MVP & MVVM).

因此,如果有任何此类文章讨论了这 3 种设计模式(MVC、MVP 和 MVVM)的代码看起来有何不同,那么请将我重定向到该文章.

So if any such article exists which discusses how code would look different for these 3 design patterns (MVC, MVP & MVVM) then please redirect me to that article.

推荐答案

一些基本的差异可以简写为:

Some basic differences can be written in short:

MVC:

传统的 MVC 是有一个

Traditional MVC is where there is a

  1. 模型:充当数据的模型
  2. View : 处理用户的视图,可以是 UI
  3. Controller:控制Model和View的交互,view调用控制器更新模型.如果需要,视图可以调用多个控制器.

MVP:

类似于传统的MVC但Controller被Presenter取代.但是Presenter 与Controller 不同,它也负责改变视图.视图通常不会调用演示者.

Similar to traditional MVC but Controller is replaced by Presenter. But the Presenter, unlike Controller is responsible for changing the view as well. The view usually does not call the presenter.

MVVM

这里的区别在于视图模型的存在.它是观察者设计模式的一种实现,其中模型中的更改也由 VM 表示在视图中.例如:如果滑块发生变化,不仅模型会更新,而且视图中显示的可能是文本的数据也会更新.所以有一个双向数据绑定.

The difference here is the presence of View Model. It is kind of an implementation of Observer Design Pattern, where changes in the model are represented in the view as well, by the VM. Eg: If a slider is changed, not only the model is updated but the data which may be a text, that is displayed in the view is updated as well. So there is a two-way data binding.

这篇关于MVC、MVP 和 MVC 之间有什么区别?MVVM 设计模式在编码 c# 方面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆