在 PureMVC 中,代理应该自己发送通知,还是通过 ApplicationFacade 发送通知?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
notifyObservers
函数是旧实现的一部分;来自代理的sendNotification
调用是可接受的方法。可以肯定,通知功能只是为了向后兼容。实际上(刚刚深入代码):实现 INotifier 的类的sendNotification
方法仅调用facade.sendNotification
,而后者又调用facade.notifyObservers,因此第二种方法与第一种方法相同 - 正如您所指出的,它只是更详细。所以,是的:首先!The
notifyObservers
function is part of an older implementation; thesendNotification
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): thesendNotification
method of a class that implementsINotifier
merely callsfacade.sendNotification
, which, in turn, callsfacade.notifyObservers
, so the second method is the same as the first - it's just more verbose as you pointed out. So, yeah: first!