PureMVC: SendNotification vs. NotifyObservers
PureMVC has two ways to dispatch a Notification. A "note" for short, is like a Flex Event but that's another story. So what's the difference? The main difference is that sendNotifiaction builds the note and sends it at the same time. It's arguments are the same as Notification. notifyObservers is perfect for when you already have a notification constructed or you have a custom implementation of notification.
sendNotification can be called from a proxy or mediator.I may have this wrong, but I don't think you can do sendNotification from a command, and I'm not sure exactly why. So if you need to dispatch an event from Command, I guess that's another use for facade.notifyObservers. You can send notifications from command, mediator, or proxy.
notifyObservers(new Notification("SomeNotificationName"));
VS
sendNotification("SomeNotificationName")
NotifyObservers can be called from the facade and other than the constructor argument, pretty much works the same way. 
3 Comments:
Hi Jonathan,
You can do sendNotification from a Command. It extends Notifier like Mediator and Proxy and inherits this.
NotifyObservers is only needed if you are sending an instance of a custom Notification subclass. Otherwise, there's no need for any notifier to create an instance of Notification.
-=Cliff>
Thanks for the clarification.
Haha, actually going back and reading my post I realized that I was way confused. Now I think I've got it.
I think what I meant to get at was that you can't "listen" for a notification from a Proxy, so it must they must be called directly by commands or from the mediator itself. I don't know how that thought manifested into not being able to send notifications from command.
One thing I found that really helped me was to go back and read the design pattern's book chapters on the patterns relating to PureMVC.
Post a Comment
<< Home