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: 2 notifications???  (Read 9593 times)
flexphp
Jr. Member
**
Posts: 17


View Profile Email
« on: March 30, 2008, 07:41:54 »

Hi there.

I know, its Sunday. so most of you are luckily not working...

Regarding notifications from proxies.
I can see 3 different info types in one ApplicationFacade constant:

For example: PRODUCT_GET_FAILURE

 - PRODUCT -> deals with the Product BO
 - GET -> the action on that BO
 - FAILURE -> result of the previous action

Generally, they are two sort of "actors" looking for that notification:

 - Product display mediator: interested to know if its about its BO (PRODUCT here), and if it was successfull (might not even worry about which action it first send)
 - User info mediator: which might not mind about the BO, but only the action and its result for displaying message such as 'Item updated' or 'List not loaded' but with an extra parameter, the level of info: 'critical' might be displayed by an Alert, 'warning' or 'info' by a status bar in the bottom of the screen.

Having a lot of BO & proxies lead to an enourmous amount of constants in the application facade.

If the notification sender could send 2 notifications instead of 1, then a MessageVO could be send in the body of the MESSAGE notification. This Message VO can have a lot of info (short text, long desc, level,...) that "business objects mediators" dont care about.

The number of constants will be divided because the need is then:
Generic constants: MESSAGE, ERROR, WARNING, INFO, FAILURE, PENDING, SUCCESS
USER (the GET info could then go inside the notification type)
PRODUCT,
...

Also, a MessageProxy could be used to keep reference of the last message and, when ConfigProxy->debug info is true, could log the messages as a shared object for the admin to check later on.

Is it Best practice?

Cheers
Patrick
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 30, 2008, 09:04:11 »

I can see 3 different info types in one ApplicationFacade constant:

For example: PRODUCT_GET_FAILURE

 - PRODUCT -> deals with the Product BO
 - GET -> the action on that BO
 - FAILURE -> result of the previous action

Hi Patrick,

You could reduce the number by a third by using the 'type' property of the notification so that you're sending.

:
sendNotification(ProductProxy.PRODUCT_GET, ProductBO, ApplicationFacade.FAILURE);
Notifies anything interested in the results of the 'product get' operation and passes along this business object. Also note that the PRODUCT_GET constant is defined on the ProductProxy, not in the ApplicationFacade. Since that Proxy will be the only one to send that note, it is the more appropriate place for such a constant.

Reviewing the Best Practices doc, I see I've not been explicitly clear on this point, although the code examples under the Mediator and Proxy sections on page 34 and 64 (of the current doc) show it in action. Although SUCCESS and FAILURE are not split out into a type there.

For the reason you state, explosion of constants in the ApplicationFacade, it is better to do it this way. Further, splitting out SUCCESS and FAILURE to a type can reduce the system-wide number of constants. This means anything interested in the results of PRODUCT_GET will be notified and will need to check the type property to determine what (if any) action to take.

Hope this helps, and I will spell it out a bit more clearly in Best Practices on the next update.

-=Cliff>
Logged
flexphp
Jr. Member
**
Posts: 17


View Profile Email
« Reply #2 on: March 30, 2008, 12:22:16 »

Thanks for your answer Cliff.

You exposed a way to cut down the number of constants.

The second part of the question was on the 2 different uses of a proxy event (success | failure...):
 - one for the display object through its mediator,
 - one to display message to the user.

Message display may have different 'depth' depending on the user (short for current user, detailled for admin?)
With icons or styling different for a 'critical' message or just warning or simple info acknowledgement.
But a MessageMediator cannot listen for all the business objects notifications (too many).
Thus, the idea was to send 2 notifications from the same event of the same proxy (proxy data success | faillure | pending) targeted to different mediators.

Good practice?

Thanks again.
(Raining sunday in France)
Cheers,
Patrick
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: March 31, 2008, 12:27:47 »

Patrick,

I think to send the 2 notifications would be coupling the model tier to the view tier too closely. The proxy is making anticipations about what the view wants, making it less portable. It is a good idea to always think in terms of eventually reusing the model tier in another app with a different view and different use cases. Thus, if the model is bending over backwards to serve one view it will be hard to reuse it.

So, in this case you have a business logic problem. Send one notification handled by a Command that multiplexes it into the notifications required by the logged user. Reduce the notification explosion with the previously mentioned methods, and perhaps by sending a complex object in the notification body to be interpreted by the Command.

Best regards,
-=Cliff>   
Logged
flexphp
Jr. Member
**
Posts: 17


View Profile Email
« Reply #4 on: April 01, 2008, 01:09:36 »

So do I understand well:

proxy:
sendNotification( ApplicationFacade.PROXY_USER_EVENT, complexObject );

facade call ProxiesEventCommand which:
  - manipulate MessageProxy to store customized & localised info
  - sendNotification( ApplicationFacade.USER, [ApplicationFacade.GET_ACTION, userVOExtractedFromComplexObject], ApplicationFacade.SUCCESS );

UserFormMediator is listening for USER and handles depending on note.getType()
MessageMediator is also listening for USER but go & search the appropriate message in MessageProxy

MessageMediator is listening for any Business Object in the project (User, Product...)

Am I right?
Thanks,
Patrick
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: April 02, 2008, 07:37:52 »

Yes, except you'd probably defined PROXY_USER_EVENT? on the Proxy.

in UserProxy:
public static const USER_EVENT:String = 'userProxyEvent';
sendNotification( USER_EVENT, complexObject );

Something like that. :)
-=Cliff>
Logged
Pages: [1]
Print