Example on Abstracting View and Mediator

Abstracting View and Mediator's Avatar

Abstracting View and Mediator

31 Aug, 2010 06:15 PM

  1. 1 Posted by Abel de Beer on 31 Aug, 2010 08:32 PM

    Abel de Beer's Avatar

    The idea of abstraction is always nice of course. In your example it is obviously cleaner to be able to leave out the necessary common Mediator inject statements, in your case view:AbstractView and signalScreenResized:SignalScreenResized.

    I applied your example to one of my current projects as an experiment and I have a few remarks:

    1. Once you start implementing your concrete views with their own public properties and methods, you're required to cast your view to the concrete view class to be able to access its API. The fact that you need to do (view as ConcreteView).publicMethod(... makes your code look more messy IMO.

    2. The fact that you're leaving out at least one necessary dependency in your concrete Mediators that needs to be injected - the view - makes your code less readable. I think this is a typical (negative) side effect of abstraction.

    I haven't decided which way to use yet.

    Nice example, thanks!

    Slightly off-topic, can someone provide me with an example where an interface is used for the injectViewAs argument of the mediatorMap.mapView method?

  2. 2 Posted by Bjeld on 01 Sep, 2010 07:53 AM

    Bjeld's Avatar

    I agree with you about it feels a bit "not right" when Casting the ConcreteView. I Often tend to make a reference to the view like concreteView:ConcreteView; and the in the onRegistrer I store the casted concreteView; concreteView = ConcreteView(view); it makes the code a bit cleaner I think.

  3. Stray closed this discussion on 16 Feb, 2011 08:59 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