模型-视图-控制器是糟糕的面向对象设计吗?

发布于 2024-11-03 17:20:11 字数 1432 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡写薰衣草的香 2024-11-10 17:20:11

相反,健康的 MVC 使用应该鼓励控制器和模型,这样模型(对象)就是动作发生的地方(这本身就鼓励封装和其他好处) OOP 原则),而控制器只是将某些请求指向对象的正确方向。

On the contrary, healthy MVC use should encourage skinny controllers and fat models, so that the models (the objects) is where the action happens (which itself encourages encapsulation and other good OOP principles), and the controllers are merely there to point certain requests in the right direction to the objects.

流绪微梦 2024-11-10 17:20:11

MVC 中没有任何内容表明 Model 应该是愚蠢的(贫血模型)。我认为拥有丰富的 Model 类是完全合适的,这消除了“经理”的需要。

话虽如此,目前流行的做法是使用 ViewModel 将数据传递给 View。 ViewModel 基本上是专为特定View 定制的Model 的投影。从View的角度来看,它可以被视为Model,是丰富的Model的外观;当然,Model 不仅仅是 ViewModel

Nothing in MVC says that Model should be stupid (anemic model). I think it is completely appropriate to have rich Model classes, which eliminate the need of 'managers'.

That being said, it is currently popular practice to use ViewModels for passing data to a View. ViewModel is basically a projection of your Model tailored specifically for a particular View. It can be regarded as Model from View's perspective, a facade for a rich Model; so of course there is much more to a Model than just ViewModel.

南风几经秋 2024-11-10 17:20:11

我不会将 MVC 称为与 OOD 一样痛苦的架构。 MVC只是一种可以应用于某些设计的OOD模式。因此,它简单并不与 OOD 竞争,它只是构建好或坏的 OOD 设计的工具之一。就像锤子无法与好的木工工艺竞争一样,锤子和MVC一样,只是工匠工具箱中的一个工具。

模式也不会助长糟糕的设计。因为良好的 OOD 设计将具有良好的关注点分离,所以 MVC 模式可以通过将表示关注点(视图)与应用程序逻辑(控制器)和更基本的域逻辑(模型)分离来为您提供这一点。因此,它是一种很好的 OO 模式,经常应用于用户界面。但在制作优秀的 OOD 时还可以考虑其他竞争模式。

I would not call MVC an architecture that is on the same pain as OOD. MVC is just an OOD pattern that can be applied in certain designs. Thus it simple does not compete with OOD and it’s just one of your tools to build a good or bad OOD design. Just like a hammer does not compete with good wood craftsmanship, the hammer, like MVC, is just a tool in the craftsman’s toolbox.

It neither is pattern that facilitates bad design. Because a good OOD design will have a good separation of concerns, the MVC pattern can provide that for you by separating the presentation concerns (view) from the application logic (controller) and the more fundamental domain logic (model). As such it’s a good OO pattern that is often applied in user interfaces. But there are other competing patterns that could also be considered while making a good OOD.

℡Ms空城旧梦 2024-11-10 17:20:11

我们有两种形式的 MVC:Pull MVC 和 Push MVC(也称为基于组件的 MVC 和遗留 MVC)。

Push MVC 侧重于概念的分离,每个模型-视图-控制器集处理应用程序的某些方面,并且可以由一些单独的人员进行工程和开发。当系统快速开发时,它运行良好,并且添加功能也很容易。大型系统中的代码重用变得很糟糕。本质上只有模型被重用。

Pull MVC,专注于通过使用小部件(视图组件)来重用代码,以便许多视图共享相同的代码,并且只自定义它们的小部件。对于控制器来说,抽象并执行常见的控制器实践。

这是根据软件的性质和速度混合拉式和推式 MVC 的问题。

We have two forms of MVC, Pull MVC and Push MVC (aka Component Based MVC and Legacy MVC).

Push MVC focuses on separation of concepts, each model-view-controller set handles some aspect of the application and can be engineered and developed by some separate people. When the system is rapidly developing, it works great, and adding features is easy too. Code re-use in larger systems gets terrible. Essentially only models are re-used.

Pull MVC, focuses on code re-use via using widgets (components of view), so that many views share the same code and only customize their widgets. As for controllers, common controller practices are abstracted and performed.

It is a matter of mixing Pull and Push MVCs depending on the nature and pace of the software.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文