Mediation of Interfaces

matej's Avatar

matej

03 Jul, 2013 01:15 PM

Currently we have one mediator for each view.
For example if we have a lot of buttons and we want to implement IClickable, we have one instance of each mediator for each button, and if we have more interfaces, like IScalable or IHideable ....

Is it possible to make implementation or certain type of mediator that has list of all views that have certain interface, and since we are manipulating interface methods it will be the same for each view.

Would this save on resources, or is there different approach to this?

  1. Support Staff 1 Posted by Ondina D.F. on 03 Jul, 2013 02:33 PM

    Ondina D.F.'s Avatar

    Hey Matej,

    Is this what you’re after?

    mediatorMap.mapMatcher(new TypeMatcher()
    .anyOf(ISpaceShip, IRocket))
    .toMediator(SpaceCraftMediator);
    

    https://github.com/robotlegs/robotlegs-framework/tree/master/src/ro...

    Ondina

  2. Support Staff 2 Posted by Ondina D.F. on 03 Jul, 2013 03:56 PM

    Ondina D.F.'s Avatar

    Maybe what you meant was this:

    FirstView implements IFirstBehaviour, ISecondBehaviour
    SecondView implements ISecondBehaviour

    And you map the behaviours:

    mediatorMap.map(IFirstBehaviour).toMediator(FirstBehaviourMediator);
    mediatorMap.map(ISecondBehaviour).toMediator(SecondBehaviourMediator);

    Then you inject IFirstBehaviour into FirstBehaviourMediator, and ISecondBehaviour into SecondBehaviourMediator

    So when FirstView is added to the stage, both mediators will be created, and you can apply both behaviours to FirstView.
    SecondView will only have the behaviour defined in ISecondBehaviour.

  3. 3 Posted by matej on 04 Jul, 2013 09:02 AM

    matej's Avatar

    Lets put it like this :)

    Is it possible to have instance of mediator for 15 buttons. They all have the same method, so when new IButton is added to stage, we just update the list inside the mediator with the new view. Currently I think we have one instance per button.
    Matej Šimunić
    Developer

    GV3 UX

  4. Support Staff 4 Posted by Ondina D.F. on 04 Jul, 2013 09:31 AM

    Ondina D.F.'s Avatar

    When you add several instances of the same view to the stage, each instance will have its own mediator.

    If you add different Views, that implement the same interface (IFirstBehaviour), and you mapped them like so:

    mediatorMap.map(IFirstBehaviour).toMediator(FirstBehaviourMediator);

    each view will have its separate mediator.

    What you’re asking is one mediator for multiple views, right?

    You are thinking of mapping the mediator as an interface? If so, as far as I know, that’s not possible. You can only map concrete mediator classes. I might be wrong though.

    Why do you think is a bad idea to map to behaviours, as I suggested in my last post?

  5. Support Staff 5 Posted by Ondina D.F. on 05 Jul, 2013 10:20 AM

    Ondina D.F.'s Avatar

    Alternative solution:

    If you need to set properties to lots of view instances and you don’t want to have a mediator for each instance of the view, you might want to consider using hooks and guards, and provide mediation through views’ parent mediator.

    Say, you mapped the views as interfaces like this:

    viewProcessorMap.mapMatcher(new TypeMatcher().anyOf(IFirstBehaviour, ISecondBehaviour))
        .toProcess(new FastPropertyInjector({colorsVO:ColorsVO}))
        .withHooks(SomeBehaviourHook)
        .withGuards(IfColorIsRed);
    

    By using the viewProcessorMap you can inject properties into your views, if you want to.
    If you don’t want to inject any properties, use .toNoProcess() instead of toProcess.

    In your hook you inject IFirstBehaviour and ISecondBehaviour and call the view’s API to let it do what you need it to do.
    The hook will do its job and then it gets gc-ed.

    If you need to let your view implementing the above interfaces send data back to the framework, you let it dispatch an event, and the mediator of the parent view can handle it (if the event bubbles = true)

  6. 6 Posted by matej on 05 Jul, 2013 11:29 AM

    matej's Avatar

    I like this, will check it out later :)

    thanks
    Matej Šimunić
    Developer

    GV3 UX

    ––––––––––––––––––––––––––––––––––––––
    Note: Privileged/Confidential information may be contained in this message and may be subject to legal privilege.
    Access to this e-mail by anyone other than the intended is unauthorised.
    If you are not the intended recipient (or responsible for delivery of the message to such person), you may not use, copy, distribute or deliver to anyone this message (or any part of its contents ) or take any action in reliance on it.

  7. Ondina D.F. closed this discussion on 18 Jul, 2013 03:00 PM.

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

Keyboard shortcuts

Generic

? 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