We're having a bit of a in-office debate on PureMVC best practice, and I wanted to get an opinion on the way I've historically been using PureMVC. I'm using the login form example from the best practice document.
I prefer to map the LOGIN_SUCCESS and LOGIN_FAILED notifications to their own SimpleCommands (eg: LoginSuccessCommand and LoginFailedCommand). These “extra” commands would call retrieve and call public methods on the LoginMediator (eg: LoginMediator.onLoginSuccess and LoginMediator.onLoginFailed) as opposed to using the LoginMediator.handleNotification switch statement.
I like this for a few reasons:
In large applications, it centralises the code into “actions” (or verbs, as I like to think of them). If I want to change the way that the application reacts to the “successful login” action, I can simply find it in one place (i.e.: LoginSuccessCommand), and have total control over which order things happen in. In the best practice example, if multiple mediators needed to react to the same notification, I either need to remember where these are or search for all matches for a notification to edit them, and I can't control the order they happen in.
Additionally, I can easily update a Proxy and a Mediator at the same time in a predetermined order. Say I needed to check or update a data object containing the application’s state (AppStateVO via AppStateProxy, for example). My LoginSuccessCommand could then call public methods or getters on the AppStateProxy before it updated the LoginMediator. If things get really complex, I would use a MacroCommand, but this is the general way I’ve been approaching this problem.
What are the issues (if any) with this from a best practice standpoint? I now do this so often that most of my applications do not utilise Mediator.handleNotification at all. I opt instead for three or four line Command.execute methods that simply retrieve Mediators and call public methods on them, exactly the same way that is recommended for using a Proxy.
Any thoughts from a best practice standpoint would be much appreciated.
Cheers.