问题描述
如果我们使用"MVC、MVP 和 MVVM 设计模式之间有什么区别"这个短语在 Google 上搜索,那么我们可能会得到很少的 URL 来讨论 MVC MVP 和 MVVM 设计模式之间的区别.MVVM设计模式理论上像
MVP
在无法通过数据上下文绑定的情况下使用.Windows 窗体就是一个很好的例子.为了将视图与模型分开,需要一个演示者.由于视图不能直接绑定到演示者,因此必须通过接口(IView)将信息传递给视图.
MVVM
在可以通过数据上下文绑定的情况下使用.为什么?删除了每个视图的各种 IView 接口,这意味着需要维护的代码更少.可以使用 MVVM 的一些示例包括使用 Knockout 的 WPF 和 javascript 项目.
MVC
在视图与程序其余部分之间的连接并不总是可用的情况下使用(并且您无法有效地使用 MVVM 或 MVP).这清楚地描述了 Web API 与发送到客户端浏览器的数据分离的情况.微软的 ASP.NET MVC 是管理此类情况的绝佳工具,并提供了非常清晰的 MVC 框架
但我还没有找到一篇从理论上讨论差异以及示例代码的文章.
如果我能得到一篇文章来讨论这 3 种设计模式(MVC、MVP 和 MVVM)之间的区别以及代码,那就太好了.
我想获得 3 个类似 CRUD 应用程序的源代码,这些应用程序已通过这三种设计模式(MVC、MVP 和 MVVM)实现.这样我就可以通过代码了解如何为这三种设计模式(MVC、MVP 和 MVVM)编写代码.
因此,如果有任何此类文章讨论这 3 种设计模式(MVC、MVP 和 MVVM)的代码看起来有何不同,那么请将我重定向到那篇文章.
这个应该是好的开胃菜.实际上,您选择的"平台"在您如何使用这些模式方面也起着重要作用.例如,MVVM 自然适用于 WPF,而 MVP 则适用于 Windows 窗体.ASP.Net MVC 不言自明.
问题描述
If we search Google using the phrase "What is difference between MVC, MVP & MVVM design pattern" then we may get few URL's which discuss the difference between MVC MVP & MVVM design pattern theoretically like
MVP
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
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 include WPF and javascript projects using Knockout.
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 discuss the difference theoretically along with sample code.
It would be really nice if i get a article which discuss the difference between these 3 design patterns (MVC, MVP & MVVM) along with code.
I'd like to get my hands on source code of 3 similar CRUD apps which has 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 patter (MVC, MVP & MVVM).
So if any such article exists which discuss how code would look different for these 3 design patterns (MVC, MVP & MVVM) then please redirect me to that article.
推荐答案
This should be a good starter. In reality, your chosen 'platform' also plays a large role in how you use these patterns. For example, MVVM is naturally suited to WPF, while MVP works well with Windows Forms. ASP.Net MVC speaks for itself.