为什么在 Flex PureMVC 中中介者与代理耦合?
我最近刚刚学习了 PureMVC 框架,对 Proxy 和 Mediator 对象之间的耦合有点困惑。 此页面上的链接连接到一些描述该框架的文档。 (请注意,上述页面上的链接会打开 PDF。)
我研究过的 PureMVC 的图表和示例通常显示中介器和代理之间的直接耦合。当代理的状态更新时,中介器(从 Facade 检索对代理的引用)不会发送新的通知,而是更新其状态。
这看起来确实简化了代码逻辑,但它也直接将两个看似不同的组件耦合在一起。据我了解,中介者的目的是将事件从视图转换为 PureMVC 通知。代理旨在执行一些功能来收集数据并将其转发回视图。这两个组件似乎存在于应用程序的不同层中,也许不一定应该耦合在一起。
让代理对象在状态更新时发送自己的通知(由外观转发给感兴趣的中介者)不是更有意义吗?
I've just recently learned the PureMVC framework, and am a little confused as to the coupling between Proxy and Mediator objects. The links on this page connect to some documents describing the framework. (Please note, the links on the aforementioned page open PDFs.)
The diagrams and examples of PureMVC I've examined often show a direct coupling between a Mediator and Proxy. When the proxy's state is updated, rather than sending a new Notification, the Mediator (which retrieves a reference to the Proxy from the Facade) has its state updated.
This certainly seems to simplify the logic of the code, but it also directly couples two seemingly disparate components together. To my understanding, a Mediator's purpose is to translate Events from a view into PureMVC Notifications. Proxies are meant to perform some function to gather data and relay it back to the view. These two components seem to exist in different layers of the application, and perhaps shouldn't necessarily be coupled together.
Wouldn't it make more sense to have the Proxy objects send their own Notifications when their state updates, which are forwarded to the interested Mediator by the Facade?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使您通过通知更新中介器,它也会耦合到代理,但没关系,它必须如此。
只要你不耦合代理,我会说没问题。
胡安
Even if you update the mediator through notifications it would be coupled to the proxy but that's ok, it has to be.
As long as you don't couple the proxy i would say it's ok.
Juan
是的,这正是需要发生的事情。 PureMVC 只是一个通知者/观察者模式实现,具有通过外观链接的轻量级 MVC 结构。我强烈建议不要将代理与中介结合起来;只允许Mediator在数据状态改变时响应Proxy发送的Notification。这允许这些类完全解耦。
如果您使用 Flex,我建议 HydraMVC / HydraFramework 是 PureMVC MultiCore 的 Flex 特定端口,模仿 PureMVC 的 API,但更简洁,并且包含一种解耦服务器交互的方法通过 DelegateRegistry 来自代理。 (坦白说,我是这个项目的主要开发人员,但它完全是 OSS,可以免费使用/贡献。)无论您实现哪种 MVC 框架,我仍然强烈建议通过通知完全解耦代理/中介器。
Yes, this is exactly what needs to happen. PureMVC is simply a Notifier / Observer pattern implementation with a lightweight MVC structure linked by a Facade. I strictly advise not to couple Proxies to Mediators; only allow Mediators to respond to Notifications that are sent by the Proxy when the data state changes. This allows those classes to be fully decoupled.
If you are using Flex, I would recommend HydraMVC / HydraFramework which is a Flex-specific port of PureMVC MultiCore, mimicking the API of PureMVC however is much less verbose, and includes a way to decouple server interaction from Proxies via a DelegateRegistry. (Full disclosure, I am the principal developer on this project, however it is fully OSS and free to use / contribute.) Regardless which MVC framework you implement, I still strongly recommend fully decoupling Proxies / Mediators via Notifications.