MVP(模型视图展示器)或 MVC(模型视图控制器) [英] MVP (Model View Presenter) or MVC (Model View Controller)

查看:23
本文介绍了MVP(模型视图展示器)或 MVC(模型视图控制器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道 MVP 和 MVC 之间的区别.然后,在通过应用程序的 SRS 之后,我得到了一个 Fix,需要选择、应用并遵循应用程序架构.根据我的理解,我会从 2 个以上的 GUI 中选择有可能使用相同业务逻辑的 MVP.就像具有公共 (www) 和 Adming (winform) 部分的应用程序一样.如果没有这样的......寻找MVC.因为我可以更准确地遵循工厂模式.

I already know the difference between MVP and MVC. Then also after going through the SRS of an application i get in a Fix which one need to be picked, applied and followed as Applcation Architecture. As per my understanding I would pick MVP where there is the chances of using the Same Business Logic, from more than 2 GUIs. Like for a application with a public (www) and Adming (winform) part. If there is not such ... look for MVC. Because I can follow Factory patters more accurately.

伙计们,我不知道,但我觉得如果我必须在他们中间做出选择,我只是盲目地投篮.我需要知道.你们对这些有什么看法?

Dudes, I don't know but I feel like I just play blind shot if I would got to choose among them. I need to know. What opinion you guys have over these?

注意:我遵循 .net 和 C#.

Note: I follow .net and C#.

推荐答案

在我看来,模型视图控制器模式的所有变体的差异 (MVP被动视图监督控制器,视图模型,)非常微妙.这完全取决于谁处理数据并从谁那里获取数据,真的.他们都试图解决同一个问题,将某事另一件事分开,而解决方案以类似的方式完成所有这些.

In my mind the differences for all variations of Model View Controller patterns (MVP, Passive View, Supervising Controller, View Model, etc.) are quite subtle. It's all about who processes the data and takes the data from who, really. They are all trying to solve the same problem, seperating something from another thing, and the solutions do all that in a similar fashion.

当您从视觉角度考虑时,几乎可以明显看出这些概念在实现上是相似的:

It is almost blatantly obvious that the concepts are similar in implementation when you think about it in visual terms:

Simplistic MVC:

+-------+       manipulates data
| Model |<---------------------+
+-------+                      |
    |                          |
    | gets data                |
    v                          |
+------------+ serves data  +------+
| Controller |------------->| View |
+------------+              +------+

Simplistic MVP:

+-------+
| Model |
+-------+
  |  ^
  |  | get/manipulates data
  v  |
+-----------+  serve data   +------+
| Presenter |-------------->| View |
|           |<--------------|      |
+-----------+  tell changes +------+

它们的相似之处在于类层次结构可能在两者中看起来相同.然而,不同之处在于显示和操作数据的不同方式.当您推出自己的 MVC 时,您将负责它的外观.

They're similar in that class hierarchy may look the same in both. The difference however are the different ways of displaying and manipulating data. When you're rolling out your own MVC then you're in charge of how it should look like.

这并不重要,因为它们都基于将代码段分离为自助逻辑实体并减少代码重复的原则.只要您保持代码耦合度低,它最终应该会很好地工作.只有当您想对应用程序的架构产生教条性后果时才重要.

It doesn't really matter that much since they are all based on a principle of seperating pieces of code into self serving logic entities and reducing code duplication. As long as you keep the code coupling low it should work out nicely in the end. It only matters if you want to be dogmatically consequent with your application's architecture.

务实,做最适合你需要的事情,因为无论如何你最终都会得到一个混合.根据视图的需要,在变体之间切换应该相当"容易.按照 SOLID 原则,你应该做得很好.(另请参阅有关 SOLID 的内容).

Be pragmatic about it and do that what suits your needs the best since you'll end up with a mix anyway. It should be "fairly" easy to switch between the variations depending on what the view needs. Follow the SOLID principles and you should do fine. (See also this about SOLID).

我建议您查看是否有 MVC 或 MVP 框架,以了解它是如何完成的.

I would suggest you look into if there are MVC or MVP frameworks to see how it is done.

这篇关于MVP(模型视图展示器)或 MVC(模型视图控制器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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