gpt4 book ai didi

model-view-controller - MVC 的最佳定义是什么?

转载 作者:行者123 更新时间:2023-12-03 12:52:29 25 4
gpt4 key购买 nike

我一直在使用带有 MVC 配置的 Zend 框架,阅读了有关 Ruby on Rails 的信息,并且我计划在 Python(Django?)中探索其他 MVC 框架。我真的很喜欢它隔离逻辑、安全性和验证的某些部分的方式。但在使用它一年后,我读到了一个答案 here说几乎每个人都对 MVC 有错误的定义,这让我想知道:MVC 的正确定义是什么,我在哪里可以阅读有关模式和标准实现的信息?

更新:我知道我们都知道 BASIC 的定义(有一个模型、一个 Controller 和一个 View , Controller 上的 Action 在用模型制作一些东西后转到带有一些信息的 View )但我很想知道你认为每个人的定义是什么知道以及为什么它是错的(也许这会向每个人解释可能存在错误的地方,意见,当然还有您对此的真实观点)

最佳答案

请参阅 Martin Fowler 所著的《企业应用程序架构模式》一书的第 14 章。

MVC 部分开始于:

"Model View Controller (MVC) is one of the most quoted (and most misquoted) patterns around. It started as a framework developed by Trygve Reenskaug for the Smalltalk platform in the late 1970s. Since then it has played an influential role in most UI frameworks and in the thinking about UI design."



它还说:

"As I think about MVC I see two principal separations: separating the presentation from the model and separating the controller from the view.

...

Of these the separation of presentation and model is one of the most important design principles in software, and the only time you shouldn't follow it is in very simple systems where the model has no real behavior in it anyway. As soon as you get some nonvisual logic you should apply the separation. Unfortunately, a lot of UI frameworks make it difficult, and those that don't are often taught without a separation.

The separation of view and controller is less important, so I'd only recommend doing it when it is really helpful. For rich-client systems, that ends up being hardly ever, although it's common in Web front ends where the controller is separated out. Most of the patterns on Web design here are based on that principle."

关于model-view-controller - MVC 的最佳定义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/425197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com