Example on Abstracting View and Mediator
link to article: http://www.martinbjeld.com/tips-and-tricks/robotlegs-abstracts/
link to source on git: http://github.com/bjeld/RobotLegsDemos
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
1 Posted by Abel de Beer on 31 Aug, 2010 08:32 PM
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
andsignalScreenResized:SignalScreenResized
.I applied your example to one of my current projects as an experiment and I have a few remarks:
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.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 themediatorMap.mapView
method?2 Posted by Bjeld on 01 Sep, 2010 07:53 AM
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.
Stray closed this discussion on 16 Feb, 2011 08:59 PM.