PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: timh on January 25, 2008, 05:54:58



Title: Adding multiple arguments to a Notification
Post by: timh on January 25, 2008, 05:54:58
Hi - I'm new to this...

What does anyone consider the best way to pass multiple arguments along with a notification?
You could make an anonymous object (sounds ugly) or you could make a ValueObject (sounds wrong for my usage).
 I'm trying to make a logger, so want to be able to send a "log" notification with 3 arguments.

Thanks

Tim


Title: Re: Adding multiple arguments to a Notification
Post by: puremvc on January 25, 2008, 06:58:58
Value objects are good for this. They are meant to shuttle data across tiers of an app. They don't have to be part of the domain model.

-=Cliff>


Title: Re: Adding multiple arguments to a Notification
Post by: timh on January 29, 2008, 09:45:44
Thanks Cliff, that makes sense.


Title: Re: Adding multiple arguments to a Notification
Post by: puremvc on January 29, 2008, 12:11:26
It doesn't always make sense to create a Value Object, though.

For instance, lets say your app has a number of view components, which dynamically have new children created, and need Mediators registered for them on the fly.

The Mediator for the view component who has just had a new child created has been listening for an event sent when the child is created.

In the handler for that event, the Mediator knows the view component that was created and the appropriate Mediator for it and wants to send a Notification containing the view component and the name of the Mediator to create.

Then, a CreateMediatorCommand hears this Notification and in a switch statement creates the named Mediator.

The issue is how to send the view component AND the name of the Mediator to create. The simplest answer is an anonymous array.

In the listening Mediator:
:

sendNotification( ApplicationFacade.CREATE_MEDIATOR, [ SomeMediator.NAME, newViewComponent ] );


In the CreateMediatorCommand:

:

var args:Array = note.getBody() as Array;
switch ( args[0] )
{
   case SomeMediator.NAME:
      facade.register( new SomeMediator( args[1] ) );
      break;

   case SomeOtherMediator.NAME:
      facade.register( new SomeOtherMediator( args[1] ) );
      break;
}


-=Cliff>


Title: Re: Adding multiple arguments to a Notification
Post by: shocks on February 07, 2008, 01:17:20
Hi Cliff

Would this be a good method for my scenario...?

I need to create a number of instances of a component on the fly (products which will be in a tile component).  Each of these has a name, image, and a description.  Additionally they will update the products proxy as the user is able to select the quantity they want of each product. 

I took a look at the examples on the Adobe site - they use custom Events.  But I'd like to make use of your excellent framework which has been great for the non dynamic elements of my app.

Cheers
Ben


Title: Re: Adding multiple arguments to a Notification
Post by: puremvc on February 07, 2008, 05:55:08
Ben,

I believe that the process I outlined makes sense for handling the deferred instantiation of Mediators in the scenario you have described. Please feel free to ask for clarification or point out any specific issues you think that it presents.

Also, in order to keep them portable, the view components themselves shouldn't update the Proxies. They should send Events that their Mediators listen for. The Mediator may update the Proxy or it may send a Notification to a Command that updates the Proxy.

-=Cliff>