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: Good practice to make custom classes extending a notification  (Read 8274 times)
therewillbealight
Newbie
*
Posts: 5

 - therewillbealight@free.fr
View Profile Email
« on: October 08, 2008, 09:21:40 »

Hi all,

I was wondering if extending the Notification class to make custom notifications is a good or a bad practice.

I sometimes would like to be sure of the kind of notifications I send and receive.

For example, let's say I have a LoginCommand calling a method in a Login proxy to get logged. Once logged, it would send a notification including a UserVO object containing information on the user retrieved from a database.

Wouldn't it be good to create a UserLoggedNotification class in this case, extending Notification, instead of a regular notification, just like we do in AS3 with custom Event classes?

Wouldn't it allow us to be sure that, for example if a mediator receives this notification, it expects the right type of notification body ? Because I find it quite disturbing that the notification body cannot be typed explicitely...

I hope you will understand my problem, thanks for your answer and sorry for my english mistakes !


Ben
« Last Edit: October 08, 2008, 09:27:44 by therewillbealight » Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 on: October 08, 2008, 04:39:21 »

I create these, but they aren't INotification objects, they are called MyNotification (as an example) so that my commands can look for a typed body and act accordingly.

There is probably a good way to do what you are asking, but I haven't spent enough time with learning how notifications get pushed about to solve it. the sendNotification() method sends a stock notification object, so that is why I use the simple method above. Hopefully Cliff will enlighten us both.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: October 09, 2008, 05:06:56 »

Its ok to do this and support remains in the framework for it. Facade.notifyObservers takes an INotification, so you can use that to send custom notes. You can't use the sendNotification convenience method anymore, since it just creates vanilla notes.

The problem is you end up having to instantiate the note yourself, and your recipient still has to cast it. And since observer notification happens against the INotification interface, you don't get the benefit of knowing at compile time that the note your sending is of the right type for the reciever in the way you would if a call was being made against a method  of a direct collaborator where the signature specifies your subclass type. Unless you also extend View and make it use your types.

So in the end, the only benefit you get is typed access to the properties, once you've successfully cast the note at the recipient. IMHO, you're better off to just send a VO or Enum as the body of a regular note if you have to cast anyway. At least you don't have to create every note you send, you can just use INotifier.sendNotification.

-=Cliff>
Logged
therewillbealight
Newbie
*
Posts: 5

 - therewillbealight@free.fr
View Profile Email
« Reply #3 on: October 10, 2008, 07:45:29 »

Thanks a lot Cliff, I think you're totally right, I didn't think about all of these problems. So it brings much more problems than what it solves, but now at mise I know why I'll keep using the standard way of doing this, thanks a lot Cliff  :D !!!
Logged
Pages: [1]
Print