WCSF 中的控制器有什么用?
我仍在努力让我的大脑专注于 MVP。 我应该使用控制器类做什么? 这是我访问数据资源的地方吗?
I am still trying to get my brain wrapped around MVP. What should I use the controller class for? Is that where I access data resources?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
控制器应该作用于模型,也许通过对数据库的服务层调用来填充模型。 通常,控制器根据来自视图的请求对模型执行操作。
视图是屏幕上的演示。
Presenter 处理视图和控制器之间的流。
将演示者和控制器分开的原因可能是这样您可以将某个控制器与不同的演示者重复使用等。
The Controller should act upon a Model, perhaps populating a model via a service layer call to a database. Usually with requests from the view the controller performs actions on the model.
The View is the presentation onscreen.
The Presenter handles flow between view and controller.
The reason for separating out presenters and controllers might be so that you can reuuse a certain controller with a different presenter etc.
在我看来,presenter 不应该与 UI 技术耦合,而应该直接与模型的服务层打交道。 应用程序中应该只有一个控制器,并且可以与 UI 技术紧密耦合。 页面导航可以在控制器中抽象。 我觉得,基于 WCSF 的 MVP-Controller 模式是原始 MVP 模式的轻微变化。
我建议实现演示者以供重用,而控制器则不然。
In my opinion the presenter should not be coupled with the UI technology and should directly deal with the services layer of the model. There should just be a single controller in the application and that could be tightly coupled with the UI technology. Page navigation could be abstracted in the controller. I feel that, WCSF based MVP-Controller pattern is a slight variation of the original MVP pattern.
Let me suggest that presenter are to be implemented for reuse while controllers are not.
MS 的 WCSF 示例中的控制器保存模块中多个演示者共享的数据,公开对共享数据进行操作的方法,并管理 Web 会话中的共享数据。 例如,NewTransfer 呈现器和 TransferHistory 呈现器使用的汇款对象列表。
1 个演示者独有的数据只能通过控制器访问,但并非必须如此。 在这种情况下,演示者可以管理数据访问和 Web 会话数据本身。
这是我在几年来查看了一些示例(例如
我不确定他们使用的“控制器”是谁的定义,但它与 MVC 中的定义不一样。
The controller in MS's WCSF examples hold data shared by multiple presenters in the module, expose methods to act upon that shared data, and manage the shared data in the web session. For instance, a list of money transfers objects used by a NewTransfer presenter and a TransferHistory presenter.
Data that is unique to 1 presenter only could be accessed through the controller, but doesn't need to be. The presenter could manage the data access and web session data itself in this case.
That's my interpretation after looking at a few examples over a couple of years, e.g.
I'm not sure whose definition of "controller" they're using, but it's not the same as the one in MVC.