PureMVC actors and their responsibilities

Model(Proxies) contains the data and business logic.
View(Mediators) presents the user interface components.
Controller(Commands) handles the user input and manipulates the model.
————————————————————————MEDIATOR————————————————————————-
Send Notifications
facade.sendNotification is used in mediator for communicate with other mediators or to trigger a Command. sendNotification also works to send information from one mediator to another.
SliderMediator.as
Listen for Notifications
Mediator takes notes of interest and responds by setting data on the component or calling methods on it to change its state.
ApplicationMediator.as
Listen for UI events, Turn events into Notifications
The Mediator listens for events fired by your view components and then transforms those into notifications when required.
DateFieldMediator.as
Set data on the component
The Mediator set the data on the view component and the component bind locally to that data.
ApplicationMediator.as
Call methods on the component
The mediator call the methods on the view component to change its state.
VideoMediator.as
Occasionally create mediators for the view component’s children
A Mediator might create another Mediator, for instance if a Mediator’s child is a ViewStack, which defers the creation of its children until you navigate to them. The same happens to a Window component in AIR. You wait until window is created, and then add mediators for the window children components.
ColorfulViewStackMediator.as, LoginWindowMediator.as
May retrieve and interact with the methods and properties exposed by the Proxy
The mediator may do simple updates directly to the model on behalf of the view component.
If you’d be making the same proxy calls from multiple mediators, it can be worthwhile to refactor those calls into commands.
BlueViewMediator.as, CarVO.as, CarsProxy.as
When to trigger Commands and when to simply manipulate Proxies directly from a Mediator
————————————————————————COMMAND————————————————————————-
Send Notifications
Command can send Notification to mediators or to trigger other Command.
StartupCommand.as
May register, retrieve and remove another Proxy or Mediator
Command may register, retrieve and remove another Proxy or Mediator at runtime.
ViewPrepCommand.as
Gather data from multiple Proxies, Manipulate data before display
If there is some complicated transformation of the Model data or it is being assembled from multiple Proxies, then we would usually call that ‘Business Logic’ and push it into a Command.
—————————————————————————PROXY—————————————————————————-
Send but do not receive Notifications
Proxies may send Notifications for various reasons, such as a remote service Proxy alerting the system that it has received a result or a Proxy whose data has been updated sending a change Notification.
They don’t listen for notifications, but are instead retrieved and manipulated by commands and/or mediators.
RssProxy.as
May interact with Proxies
There’s no problem at all with a proxy registering, retrieving or removing another Proxy. You can let the proxies know about each other and form their own hierarchies.
CarOwnersProxy.as
Call Service
The proxy should be calling the service and retrieve the data from it.
RssProxy.as


Cliff Hall
May 28, 2009 at 11:24 pm
Excellent examples and presentation here, Mariush. The CarOwnersProxy is particularly well conceived.
-=Cliff>
Tom
May 29, 2009 at 10:07 am
Well done
Arno
June 23, 2009 at 3:00 pm
If the command’s function is to manipulate data before display how does he get this data? When you receive the data in the proxy you send a notification that you receive in the mediator. Or do i get something wrong? Or are you allowed to receive notifications in the command?
thank you in advance
Mariush T.
June 23, 2009 at 10:28 pm
There are two ways of getting this data in Command:
1.You can retrieve proxy and get the data
var usersProxy:UsersProxy = facade.retrieveProxy( UsersProxy.NAME ) as UsersProxy;
var users:ArrayCollection = usersProxy.users;
2.Proxy can send data together within Notification, Command gets data from the body of Notification
var users:ArrayCollection = notification.getBody() as ArrayCollection;
DeleteUserCommand
Yes, You’re right. Proxy sends Notification, interested mediators receive notification or commands are triggered. Commands are not allow to receive notification, they are instantiated and executed by the Controller. In order to trigger command, you need to register Command. registerCommand(CategoriesProxy.CATEGORIES_RECEIVED, ManipulateDataCommand).
public class ManipulateDataCommand extends SimpleCommand
{
override public function execute(notification:INotification):void
{
var categories:ArrayCollection = notification.getBody() as ArrayCollection;
.. manipulate data
}
}
To better understand Commands, think about Commands as an object with only 1 second lifecycle, they are instantiated, executed and gone. There is no time for them to listen for notification in such a short period of life
Arno
June 24, 2009 at 6:59 am
Thanks for the example and explanation. It is much clearer now
Sean
April 23, 2010 at 12:52 pm
Thanks for the help, your example is excellent