模型- View - Controller : View 的更改何时应由 Controller 确定?

标签 model-view-controller design-patterns

Model-View-Controller 似乎允许对 View 进行两种类型的更改:

  1. 每当模型发生更改时, View 都会收到更改通知,因此它可以相应地更新其视觉表示。
  2. 出于“ View 选择”的目的, Controller 可以直接访问 View 的 API。

“ View 选择”到底是什么?在什么情况下 Controller 应该对 View 进行更改,而不是让 View 仅根据模型进行自己的更改?

最佳答案

这是一篇您可能会觉得有用的文章。

Modified MVC Pattern

作者介绍了一个 MVC 流程,其中模型将通知发送到 Controller (而不是传统方式中的 View )。因此, Controller 在两个方向上调节模型和 View 对象之间的数据流。正如他们所说

This design helps to more completely decouple the model from the view. In this case, the controller can dictate the model properties that it expects to find in one or more models registered with the controller. In addition, it can also provide the methods that effect the model's property changes for one or more views that are registered with it

... 这是您关于什么是 View 选择的问题的答案。基本上只是应用程序具有一系列根据模型中的单个更改相关或更新的 View 。 Controller 将决定需要更新和/协作哪一组 View 来完成工作(来自一个 View 的信息是不够的)

关于模型- View - Controller : View 的更改何时应由 Controller 确定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/821487/

相关文章:

c++ - protected 外部资源使用

Java MVC,添加屏幕使用什么模型?

java - 获取xml数据

c++ - 如何在 C++ 中获取通过 C 回调返回的结果

c# - 在不破坏类结构的情况下在包含的类中向量化操作

javascript - MVC 中的 Ajax POST

javascript - 如何将逻辑分解为 Node 中的 Controller 和模型

java - spring mvc表单提交异常处理模式

asp.net - 尝试使用 Paypal API 时出现错误 500.19

python - 在 Python 中实现装饰器模式