tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/21-subclassing-mediatorsRobotlegs: Discussion 2018-10-18T16:35:07Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/7132982009-12-11T20:39:09Z2009-12-11T20:39:11ZSubclassing Mediators<div><p>I have a set up where I have a mediator that subclasses another.
They both control the same kind of component (a TileList in this
case). The view property of the superclass is set to be injected
with a TileList, which is then inherited by the subclass. What I'm
trying to figure out is how to tell the context to inject the
superclass in one case and the subclass in another.</p>
<p>Is there a method for handling this kind of scenario? I saw
Joel's suggestion of using a setter injection elsewhere (here, in
fact: <a href=
"http://knowledge.robotlegs.org/discussions/problems/8-multiple-views-controlled-by-one-mediator">
http://knowledge.robotlegs.org/discussions/problems/8-multiple-view...</a>)
but the topic was slightly different in that case, so I wasn't sure
if it was relevant.</p>
<p>Owen</p></div>Owentag:robotlegs.tenderapp.com,2009-10-18:Comment/7132982009-12-11T20:52:21Z2009-12-11T20:52:21ZSubclassing Mediators<div><p>Hi Owen,</p>
<p>I think the best solution here is to create an abstract mediator
that you extend into the two subclasses. Subclassing a concrete
Mediator that already has it's view component dependency defined is
always going to be tricky to work around - and not a very clean
approach when you think about what you're extending and what you're
trying to swap out (the view dependency).</p>
<p>Does that help?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/7132982009-12-11T21:26:14Z2009-12-11T21:26:19ZSubclassing Mediators<div><p>Hi,</p>
<p>Thanks for the swift reply! The view used by both Mediators is
the same. The problem I have is that I can't figure out how to
assign different Mediators to the same view class.<br>
In the context I'd have (FlickrTileListMediator extends
PaginatedTileListMediator):</p>
<p>mediatorMap.mapView( TileList, PaginatedTileListMediator );<br>
mediatorMap.mapView( TileList, FlickrTileListMediator );</p>
<p>But obviously, the second mapping has the same view as the
first. I don't know if it's possible to use a named mapping in this
case?</p>
<p>I can see a solution that uses the approach you've described,
which would be to extend TileList and PaginatedTileListMediator and
use those to map instead.</p>
<p>Something like:<br>
mediatorMap.mapView( TileList, StandardTileListMediator );<br>
mediatorMap.mapView( FlickrTileList, FlickrTileListMediator );</p>
<p>Do you think that'd be the best approach?</p></div>Owentag:robotlegs.tenderapp.com,2009-10-18:Comment/7132982009-12-11T21:36:50Z2009-12-11T21:36:50ZSubclassing Mediators<div><p>Aha! So you'd like to map multiple Mediators to a single
concrete view component inside a context? That's not possible with
the way RL currently handles it's mappings - it might be possible
in the future. For now, you'd have to extend one of the view
components like you suggested. But I believe you'd need to use the
third param to indicate the injection type for the mapping:</p>
<p>Something like:<br>
mediatorMap.mapView( TileList, StandardTileListMediator );<br>
mediatorMap.mapView( FlickrTileList, FlickrTileListMediator,
TileList );</p>
<p>These limitations are performance related - we haven't thought
of a minimal-impact solution to this kind of mapping. Yet :)</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/7132982009-12-11T22:25:00Z2009-12-11T22:25:04ZSubclassing Mediators<div><p>That worked a treat. Thanks for your help :)</p>
<p>I realised that actually I didn't need to create an abstract
mediator, since what I needed to do was to provide a second view
for the mapping. In fact, I couldn't anyway since most of the code
in the base class relied on having the view.</p>
<p>So, now I have 2 views, PaginatedTileList, which maps to
PaginatedTileListMediator (the super class) and FlickrTileList,
which maps to FlickrTileListMediator (the sub class). I don't think
I needed to have PaginatedTileList at all, but thought it best,
since I'm bound to need another kind of tile list somewhere else
;)<br></p></div>Owen