Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Strongly Typed Notifications and Commands?  (Read 5463 times)
gordonp
Newbie
*
Posts: 5


View Profile Email
« on: August 06, 2009, 09:39:44 »

If there a useful convention around this or any modules that would enable this?

The idea is as follows. I use the Notifications to shuttle various data objects (VOs) around the app. Sometimes I kind of use the command as a traditional function. I provide an input data object and then return a certain result or open a specific view. The kind of data doesn't seem to logically fit in a Proxy because it is very fleeting. It only really needs exist temporarily so it makes sense to pass the data structure around the app using Notifications. However, it would be nice to get some code hinting when I construct my sendNotification() calls in Flex Builder. And apart from that I would like to have a consistent way of formulating my commands to either return an error notification if the command note.getBody() receives the wrong type of object or else complete successfully.

Perhaps in the Facade there should be a way to register a specific data type that a command can receive in note body parameter.

Are there any common guidelines around this? Am I just not thinking deeply enough about the Proxy pattern?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 07, 2009, 07:19:30 »

The sendNotification method is a convenience, as is the notification body. Events don't allow passing data at all unless you create custom Event classes. With notifications, at least you can pass anything. If you want strongly typed notifications, you can eschew the sendNotification method and use the Facade's notifyObservers method. This means you'll need to create your own custom notification class and instantiate it yourself.

It won't do you a lot of good though, since the other end has to cast the notification to the correct type. You could add a method to the facade that does something like sendNotification but with a custom type, so that you can get code hints when you are sending the note.

Personally, I don't run into many issues with the broadly typed notification system. It gives me convenience and very little downside. When I'm working on the code for sending or receiving a notification I generally know what the use case needs and if I'm looking at someone elses app, I can pretty easily track down the senders and receivers and see what's going on. Thus, the hassle of having to create typed notes has never been one with much lure.

-=Cliff>
Logged
Pages: [1]
Print