Specifying an Mediator interface instead of Mediator class in the function ---> toMediator(<Interface> );

vishwas.gagrani's Avatar


29 Mar, 2013 07:34 AM

I successfully used an Interface in the map function of mediatorMap, so that if any type of "SWF" is called, having classes that implements a given interface, it triggers the creation of mediator for that class.

mediatorMap.map(Interface or Class).toMediator(Mediator Class );

I was intrigued to know if i can do something like this too :

mediatorMap.map(Interface ).toMediator(Interface);

Bit doubtful, how can something like this can work ? Which class would the mediator instantiate in the above case ?

  1. Support Staff 1 Posted by creynders on 29 Mar, 2013 08:37 AM

    creynders's Avatar

    No, you can't and IMO it doesn't really make sense. Mediators are tightly coupled to an interface/class, by definition, so you wouldn't benefit from adding an extra abstraction to it.
    The only reason I could see to allow this is when you're mapping the same mediator to a large number of different interfaces/classes, but that's definitely a code smell that your mediator is doing too much and violates SRP.
    But maybe I'm mistaken and this could be really beneficial. If you can think of a use case let us know!

  2. 2 Posted by vishwas.gagrani on 30 Mar, 2013 05:27 AM

    vishwas.gagrani's Avatar

    mediatorMap.map(Interface ).toMediator(Mediator Class ); <<< map() parameter is "interface", toMediator() parameter is a "class" .

    The above is what i am actually doing presently. In my present project, I need to attach a single Mediator with an unknown number of Views ( sort of plugins).The application is divided into two sections. One is the main application. While the other section is view ("plugin") creator. The main application creates a set of interface in an "swc" . This swc can then be used by another section to create views. This section creates "swf" as views. Which is accessed by "main" application via an xml file. Their can be "n" number of views ( implementing particular interface, known to main application)

    When the main application is run, it shows the "n" number of tabs ( views/plugins) , depending upon the entries done in the xml file.

    However, what i was asking was this :

    mediatorMap.map(Interface ).toMediator( Interface ); // << NOTICE that unlike above case, the parameter of toMediator() too is an interface. Not a class.

    However, this one seems like, will produce an error.. as i think, there must be some concrete specification as a parameter to toMediator() , otherwise, how would it know, which class to instantiate.


  3. Support Staff 3 Posted by creynders on 30 Mar, 2013 10:31 AM

    creynders's Avatar

    Yes, it will produce an error. You can only map concrete classes as mediators.

  4. vishwas.gagrani closed this discussion on 01 Apr, 2013 08:25 PM.

  5. vishwas.gagrani re-opened this discussion on 01 Apr, 2013 08:26 PM

  6. 4 Posted by vishwas.gagrani on 01 Apr, 2013 08:26 PM

    vishwas.gagrani's Avatar

    ok. thnx!

  7. vishwas.gagrani closed this discussion on 01 Apr, 2013 08:27 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac