Here are notes that I wrote down during Javier Julio’s PureMVC talk at FITC Amsterdam a couple of weeks ago. I intend to use pureMVC and they’ll be a useful reference when the time arrives. If I have glaringly misconstrued anything please let me know
The Proxy and Mediator
- The Proxy typically sends notifications
- The Mediator receives notifications and can also send notifications
- The Proxy is located in the Model and is a natural location for domain logic, something that tends to be wrongfully be placed in Commands
- The Mediator performs the key task of separating the View and Model (which is the responsibility of the Controller in Cairngorm)
- The Mediator and Proxy have a similar setup
- Methods to override in the Mediator include;
- Since service interaction occurs in the Proxy (located in the Model), commands in the Controller are limited to things like; startup, shutdown.
- A Command is used when you want to do multiple things in response to a notification.
- Mediators can directly call methods on the Proxy instead of sending a notification. You don’t have to create a Command for everything.
- Method to override in Command
- Facade is where you retrieve, register and remove actors.
- The Proxies, Mediators and Commands all have access to the Facade.
- Some of the methods to override in Facade:
Javier got in touch with me and kindly pointed out a couple of things that I had got wrong and also offered some encouragement. These are a few points he made (I’ve made the amendments to my notes above):
“The Proxy contains controller-like code but is actually in the Model part of the architecture”
Javier – I’m not sure where you picked up this one but definitely not the case, or at least not for the Proxy. You’ll find that the Mediator already acts like a controller and that can trip people up about the framework. The reason for this is that the Mediator already does the key job of separating the View Component from the Model (e.g. a or many Proxy class) thus you don’t really have a huge need for commands, in fact very little. This is expected and because the Mediator essentially acts like a controller.
“…Controller are limited to things like; startup, shutdown, database calls.”
Javier – I could be misunderstanding database calls here as you could mean that a Proxy that makes a call to the server to fetch data from a database but was triggered by a command. Or say an AIR app that can interact with SQLite. But things like that you want to avoid having in the Command and move into the Proxy. This is one of the big differences between PureMVC and other frameworks because by moving service interaction into the model we can achieve portability and reusability.
“Mediators can directly call methods on the Proxy instead of sending a notification sometimes. You don’t have to create a Command for everything.”
Javier – Cliff Hall, the creator of PureMVC, and others, especially myself couldn’t be more proud. You learned probably one of the most important things to take away from the presentation. A lot of people get this wrong. I use the word “wrong” as Cliff has stated very good reasons why this is not only acceptable in the framework but pushed for you to do. Don’t create a command class for an action that only ever happens in one place, you are just doing more work and adding more bloat.