关于MVC的问题(一般而非网络相关) [英] A question concerning MVC (general, not web related)

查看:87
本文介绍了关于MVC的问题(一般而非网络相关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个班级收集Controller和View是一个很大的罪行吗?



为什么这个问题:

从我的角度来看,Controller而View本质上主要通过一个框架给出,如WinForm,WPF,浏览器前端......并且已经非常强大。



什么是强有力的论据仍然将Controller和View分开?



一条注意 - 我认为 - 很重要:对我来说,所有逻辑都需要在模型中实现。我永远不会在Controller中实现逻辑。



我不希望得到最终答案。更多我会很高兴看到一些优点和缺点,如果它可能是太一般的任务很抱歉



非常感谢你提前

Is it a big crime to collect Controller and View in one class?

Why this question:
From my perspective, Controller and View by nature is mostly given through a "Framework" as WinForm, WPF, browser frontend... and bound already there very strongly.

What is a strong argument to still separate Controller and View?

A note which - I think - is important: For me all logic needs to be implemented in Model. I would never implement logic in Controller.

I don't expect a final answer. More I will be happy to read some pros and cons and sorry if it is maybe a too General quest

Thank you very much in advance

推荐答案

至少可以说,在一个班级中,这将是奇怪的。但是,正式地说,MVC是一种架构模式,它并不真正关心类。它更具概念性,可以适用于许多不同的编程模型,甚至是那些没有类的编程模型(例如,使用JavaScript)。因此,再次,非常正式而非实际,这两个部分的架构可以收集在一个类中,但那么它可能是一个很大的滥用类,忘记了实际的原因。如果你想练习这种方法,你可以使用的一个反模式尤其是上帝对象

https://en.wikipedia.org/wiki/God_object [ ^ ]。



所以,我不知道这样的想法怎么可能访问你介意。 :-)



关于逻辑的位置,这有点模糊概念,所以它取决于你所谓的逻辑。我甚至不会这样想。控制器可以将命令发送到模型和视图,从而在它们之间提供某种可能的松散耦合。这种耦合也有一些逻辑背后,或者可以称之为逻辑的东西。但是,它仍然是直接管理应用程序的数据,逻辑和规则的模型:

https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller [ ^ ],

< a href =https://en.wikipedia.org/wiki/Loose_coupling> https://en.wikipedia.org/wiki/Loose_coupling [ ^ ],

,毕竟 https://en.wikipedia.org/wiki/Logic [ ^ ] :-)。



-SA
Having then in one class would be weird, to say the least. However, formally, MVC as an architectural patterns, which is not really concerned with classes. It is more conceptual and could be suited to many different programming models, even those without classes (take JavaScript, for example). Therefore, again, quite formally and not practically, those two parts of architecture could be collected in one class, but then it could be a big misuse of classes, forget practical reasons. If you want to practice this approach, one anti-pattern you could use would be, in particular, God Object:
https://en.wikipedia.org/wiki/God_object[^].

So, I have no clue how such idea could even visit you mind. :-)

As to the location of the "logic", this is somewhat fuzzy concept, so it depends on what you call "logic". I would not even think in such terms. The controller can send commands to a model and to a view, thus providing some kind of, presumably, loose coupling between them. Such coupling also has some logic behind, or something one could rightfully call "logic". But still, it's the model which "directly manages the data, logic and rules of the application":
https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller[^],
https://en.wikipedia.org/wiki/Loose_coupling[^],
and, after all, https://en.wikipedia.org/wiki/Logic[^] :-).

—SA


这篇关于关于MVC的问题(一般而非网络相关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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