在 PureMVC 中,代理应该自己发送通知,还是通过 ApplicationFacade 发送通知?

发布于 2024-08-02 22:37:46 字数 573 浏览 3 评论 0原文

PureMVC 框架中,代理通过通知与 ApplicationFacade(以及任何感兴趣的组件)进行通信。该通知应该通过它们自己的实例发送,还是通过 ApplicationFacade 的 Singleton 实例发送?坦白说,这有关系吗?

以下是执行此操作的两种方法(在 Flex/AS 中):

// from the proxy itself
this.sendNotification(ApplicationFacade.NOTIFY_ALL);

// via the ApplicationFacade instance
ApplicationFacade.getInstance().notifyObservers(new Notification(ApplicationFacade.NOTIFY_ALL));

第二种方法对我来说看起来更冗长且不太直观。此外,代理具有发送通知的能力,在我看来,这意味着它可能应该。是否存在代理应仅通过 ApplicationFacade 实例发送通知的实例?

In the PureMVC framework, Proxies communicate with the ApplicationFacade (and thus any interested components) via a Notification. Should this Notification be sent via their own instance, or the Singleton instance of the ApplicationFacade? Frankly, does it matter?

Here are two ways of doing this (in Flex/AS):

// from the proxy itself
this.sendNotification(ApplicationFacade.NOTIFY_ALL);

// via the ApplicationFacade instance
ApplicationFacade.getInstance().notifyObservers(new Notification(ApplicationFacade.NOTIFY_ALL));

The second method looks more verbose and less intuitive to me. Moreover, the Proxy has the ability to send Notifications, which, in my mind, means it probably should. Are there instances where the Proxy should only send a Notification via the ApplicationFacade instance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2024-08-09 22:37:46

notifyObservers 函数是旧实现的一部分;来自代理的 sendNotification 调用是可接受的方法。可以肯定,通知功能只是为了向后兼容。实际上(刚刚深入代码):实现 INotifier 的类的 sendNotification 方法仅调用 facade.sendNotification,而后者又调用facade.notifyObservers,因此第二种方法与第一种方法相同 - 正如您所指出的,它只是更详细。所以,是的:首先!

The notifyObservers function is part of an older implementation; the sendNotification call from the proxy is the acceptable method. Pretty sure that the notify function is just for backwards compatibility. Actually (just poked into the code): the sendNotification method of a class that implements INotifier merely calls facade.sendNotification, which, in turn, calls facade.notifyObservers, so the second method is the same as the first - it's just more verbose as you pointed out. So, yeah: first!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文