Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Mediators that Modify Proxies, only. No View  (Read 13347 times)
giannif
Newbie
*
Posts: 1


View Profile Email
« on: March 26, 2008, 08:05:46 »

A recurring need for me is to have a proxy be manipulated when various notifications are sent.
I create a mediator that lists it's notification interests, and then modifies the proxy. These could be separated out into commands, but I am only modifying one proxy - the structure is appealing, the code is centralized.

I'm about to do this for the 5th time in application, and wanted to post about it.

Is this good practice? Is anyone else doing this? Is it really a Mediator?

Here's an example - I have reporting for my video player, and my reporting "mediator" reports when it receives notifications from the system.

ReportingMediator... {

override public function handleNotification(notification:INotification):void {
   switch (notification.getName()) {
      
      case ApplicationFacade.ON_MEDIA_READY:
         _reportingProxy.onMediaReady();
         break;
         
      case ApplicationFacade.ON_MEDIA_ENDED:
         _reportingProxy.onMediaEnd();
         break;
                ..................




Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 26, 2008, 01:13:05 »

I think this is perfectly fine. The mediator in question has a well defined role and doesn't really violate any best practice and is much more maintainable than a bunch of commands to do the same one-liners.

-=Cliff>
Logged
Elephant
Newbie
*
Posts: 9


View Profile Email
« Reply #2 on: April 15, 2008, 08:22:33 »

This could just as easily be done in a command.  Simply include the switch statement as the body of the command and then register the command with all the necessary Notifications.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: April 15, 2008, 10:04:18 »

True, it could as easily be done in a Command. But with each new class a program becomes more complex. And complexity is what defines the bounds of Mankind's ability to maintain the monsters he makes. So it should always be asked if a class is truly required.

If you do these actions in more than one place then you might be better served to put the logic into a Command. If not, and a way exists to do a thing that does not violate any known best practices or make the app less maintainable, then I choose less complexity every time by application of Einstein's maxim 'As simple as possible, but no simpler'.

You can always refactor to a Command if it becomes possible to reuse the code.

-=Cliff>
Logged
galeto
Newbie
*
Posts: 3


View Profile Email
« Reply #4 on: May 02, 2008, 06:17:01 »

Just wondering, your ReportingMediator is not monitoring any view right? just some kind of stand alone listener class?

Logged
ryebrye
Newbie
*
Posts: 7


View Profile Email
« Reply #5 on: June 09, 2008, 09:35:56 »

Since the mediator in this case doesn't mediate for any view - there are three differences I see between how using a mediator and using a command to do the same thing.

1: The mediator knows what it is interested in hearing about - and is able to tell the facade exactly what it wants to know about when it registers its notification interests. A command has to have its interests told to it - and it relies on something else to register its notification interests.

2: The mediator is named "mediator" and the command is named "command"

3: The mediator / controller can coexist with other mediators / controllers that listen for the same notification. (The command map in the controller only stores the last command to be registered for a given INotification )

It seems that a mediator can duplicate every function of a command - with the added bonus that it can list its own notification interests up front without having to be registered by something else.

How much of a heresy would it be to build an app with a set of Mediators with null view components in place of all the commands? You could even name them commands and put them in a directory where commands normally go in your source tree - but instead of extending Command simply extend Mediator.
Logged
2domby
Newbie
*
Posts: 2


View Profile Email
« Reply #6 on: September 26, 2008, 07:51:09 »

How much of a heresy would it be to build an app with a set of Mediators with null view components in place of all the commands? You could even name them commands and put them in a directory where commands normally go in your source tree - but instead of extending Command simply extend Mediator.


Yes, that is what I am thinking about, too! I am very new to all this stuff, can anyone explain? I would love to hear more about that, because that is one of my biggest problems: when do I use Commands? ??? It seems, that in most (if not all) cases, Mediators and Proxies would suffice.

[sorry for bad english, I'm german]

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #7 on: September 27, 2008, 04:56:54 »

Since you posted affirmatively to it,I'm going to assume you found what you needed regarding when to use Commands here: http://forums.puremvc.org/index.php?topic=476

As far as replacing Commands with Mediators, not a good idea. Commands are meant to be stateless and go away when executed. Mediators are long lived and intended to mediate communications with the view. It would be a strange distortion of role and responsibilities, for which I can't see any upside.

-=Cliff>
Logged
Pages: [1]
Print