Model-View-Controller 似乎允许对 View 进行两种类型的更改:
- 每当模型发生更改时, View 都会收到更改通知,因此它可以相应地更新其视觉表示。
- 出于“ View 选择”的目的, Controller 可以直接访问 View 的 API。
“ View 选择”到底是什么?在什么情况下 Controller 应该对 View 进行更改,而不是让 View 仅根据模型进行自己的更改?
最佳答案
这是一篇您可能会觉得有用的文章。
作者介绍了一个 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/