在MVC模式中,模型可以交互/修改视图吗? [英] In MVC pattern, can the Model interact / modify the View?

查看:276
本文介绍了在MVC模式中,模型可以交互/修改视图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Wikipedia上以这种方式描述了MVC模式组件的交互:

The MVC pattern component interactions are described this way on Wikipedia:

模型负责管理应用程序的数据.它 从控制器接收用户输入. 视图表示演示 以特定格式显示的模型.控制器响应 用户输入并在数据模型对象上执行交互. 控制器接收输入,可选地对其进行验证,然后传递 模型的输入.

The model is responsible for managing the data of the application. It receives user input from the controller. The view means presentation of the model in a particular format. The controller responds to the user input and performs interactions on the data model objects. The controller receives the input, optionally validates it and then passes the input to the model.

我知道View应该不能与Model交互.但是在我在网上找到的大多数图表中,MVC都是这样表示的:

I understand that the View should not be able to interact with the Model. But in most of the diagrams I find on the net, MVC is represented like this:

我们可以看到模型确实可以与View交互并且可以对其进行修改,但这没有任何意义. 模型是否不会更新用于更新视图控制器?

We can see that Model does interact with the View and is able to modify it, and it doesn't make sense. Doesn't the Model update the Controller, that updates the View?

我想念什么?

推荐答案

MVC体系结构创建于1970年代.显然当时没有互联网.在原始版本中,模型通过数据绑定(也称为发布/订阅,也称为观察者模式)直接更新视图.

The MVC architecture was created in the 1970s. Obviously there was no Internet at that time. In the original version, the Model directly updates the View through data binding, also known as publish/subscribe, also known as the Observer Pattern.

《四个设计模式的帮派》一书详细描述了这种MVC体系结构. 此处.

The Gang of Four Design Patterns book describes this MVC architecture in detail. A couple of quotes from that book are in another answer here.

MVC架构非常流行,当Internet出现时,开发人员希望继续使用它.但它不适用于客户端/服务器应用程序.这样就诞生了"WebMVC",这是您今天最常见的版本. WebMVC通常实现为分层体系结构,而原始体系结构则不是.

The MVC architecture was very popular, and when the Internet came along, developers wanted to continue using it; but it didn't fit nicely into client/server applications. Thus was born "WebMVC", the version you most commonly see today. WebMVC is typically implemented as a layered architecture, which the original was not.

将两种体系结构混合在一起时会产生混乱.通常两者都简称为MVC.更糟糕的是,诸如MVP和MVVM之类的相关架构可以称为MVC.

Confusion ensues when the two architectures are conflated. Often both are referred to simply as MVC. Even worse, related architectures such as MVP and MVVM can be called MVC.

个人而言,我发现台式机MVC和Web MVC之间的关系有点像Java和JavaScript之间的关系.后者背负着前者的著名名称,以实现截然不同的东西.

Personally, I find the relationship between desktop MVC and web MVC somewhat like the relationship between Java and JavaScript. The latter piggybacked on the famous name of the former, to implement something significantly different.

相关:在视图与模型不互动?

这篇关于在MVC模式中,模型可以交互/修改视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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