1. I am keen to pass arguments directly from commands to mediators through exposed public methods, but am under the impression that I should always use notifications to do this?
Sometimes this is needed if a command is doing a lot of complex logic that involves two-way communications with various Mediators. In this case, you often need to expose methods on the Mediators and invoke them from Commands. This happens, but it is rare.
99% of Commands don't need to do this, and by sending notes instead of retrieving the Mediator and invoking a method on it, you are more loosely-coupled, and in OOP, this is generally considered a good thing.
2. If I am sending a notification that is picked up by many different 'types' of mediators, would it not be more logical for that one notification to be registered with a single command, and then have that command send out more specific notifications to interested mediators?
Certainly.
1. user clicks a button to open a previously saved document.
2. the document thumbnail viewer mediator sends a notification asking if another document is about to be overwritten: GET_CANVAS_AVAILABLE.
3. The note is received by command A which directly asks the canvas mediator if its view is empty (and thus ready to receive a new document because there's no risk of overwriting anything).
4. Assuming it is empty, command A then sends another note back to thumbnail viewer: CANVAS_IS_AVAILABLE.
There is absolutely no need for the Command in this case. OPTIMIZE like so:
1. user clicks a button to open a previously saved document.
2. the document thumbnail viewer mediator sends a notification asking if another document is about to be overwritten: GET_CANVAS_AVAILABLE.
3. The canvas mediator hears this and if its view is empty sends another note back to thumbnail viewer: CANVAS_IS_AVAILABLE, otherwise it sends CANVAS_NOT_AVAILABLE.
5. Thumbnail viewer then directly calls a public method in documentProxy and passes a document id so the doc can be retrieved from a remote DB.
6. the proxy then immediately sends another note to disable the application while the download is in progress (this is picked up by the application mediator): APPLICATION_DISABLE.
This is where a Command is needed. The responsibility for disabling the app does not lie with the Proxy, whose only concern is the Model. Nor does it lie with the Mediator who is asking for the data. This is what commands are for. Coordinating activities that affect both the View and Model. Give it a try like this:
5. Thumbnail viewer sends a notification called GET_DOCUMENT with Document ID in the body, which triggers a Command.
6.1 The Command then sends another note to disable the application (this is picked up by the application mediator): APPLICATION_DISABLE.
6.2 The Command then fetches the DocumentProxy and calls a public method, passes a document id so the doc can be retrieved from a remote DB.
The rest looks pretty standard.
Cheers,
-=Cliff>