tag:robotlegs.tenderapp.com,2009-10-18:/discussions/resources/36-example-on-abstracting-view-and-mediatorRobotlegs: Discussion 2018-10-18T16:35:37Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/27645342010-08-31T18:15:26Z2010-08-31T18:15:27ZExample on Abstracting View and Mediator<div><p>link to article: <a href="http://www.martinbjeld.com/tips-and-tricks/robotlegs-abstracts/">http://www.martinbjeld.com/tips-and-tricks/robotlegs-abstracts/</a><br />
link to source on git: <a href="http://github.com/bjeld/RobotLegsDemos">http://github.com/bjeld/RobotLegsDemos</a></p></div>Abstracting View and Mediatortag:robotlegs.tenderapp.com,2009-10-18:Comment/27645342010-08-31T20:32:37Z2010-08-31T20:45:18ZExample on Abstracting View and Mediator<div><p>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 <code>view:AbstractView</code> and <code>signalScreenResized:SignalScreenResized</code>.</p>
<p>I applied your example to one of my current projects as an experiment and I have a few remarks:</p>
<ol>
<li><p>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 <code>(view as ConcreteView).publicMethod(...</code> makes your code look more messy IMO.</p></li>
<li><p>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.</p></li>
</ol>
<p>I haven't decided which way to use yet.</p>
<p>Nice example, thanks!</p>
<p>Slightly off-topic, can someone provide me with an example where an interface is used for the <code>injectViewAs</code> argument of the <code>mediatorMap.mapView</code> method?</p></div>Abel de Beertag:robotlegs.tenderapp.com,2009-10-18:Comment/27645342010-09-01T07:53:20Z2010-09-01T07:53:21ZExample on Abstracting View and Mediator<div><p>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 <em>concreteView:ConcreteView; and the in the onRegistrer I store the casted concreteView; </em>concreteView = ConcreteView(view); it makes the code a bit cleaner I think.</p></div>Bjeld