tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/979-creating-views-from-model-service-vosRobotlegs: Discussion 2012-11-07T06:13:39Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/177026772012-07-30T23:34:53Z2012-11-07T06:13:38ZCreating Views from Model / Service VO's<div><p>What's wrong with (1)? I've always had no issue passing VOs to
views.</p>
<p>Otherwise, you could loop through the list in your mediator and
call an API for the relevant data:</p>
<p>for person in peopleList:</p>
<pre>
<code>scrollView.createScrollViewCell(person.id, person.name, person.age);</code>
</pre>
<p>Then the ScrollViewCell can store the ID, so if the "remove"
button on a ScrollViewCell is clicked, the mediator can pass on the
ID to the remove command, or whatever.</p>
<p>But while not passing the actual VO avoids coupling, you're sort
of coupled anyway: if you change person.age to person.birthday then
you will have to go through and fix the mediator and views anyway.
Passing the actual VO makes this relationship more explicit rather
than pretending it's not there. I think of VOs as being light
weight and suitable for passing around anyway; if passing the VO
means the view is getting a lot of unrelated data then maybe the VO
is taking on too much and should be split up anyway.</p>
<p>I definitely wouldn't create views in your commands, what if you
wanted three separate views to be creating different subclasses of
ScrollViewCells in reaction to the same events? The command would
quickly grow unwieldy.</p></div>stuarttag:robotlegs.tenderapp.com,2009-10-18:Comment/177026772012-07-30T23:41:46Z2012-11-07T06:13:39ZCreating Views from Model / Service VO's<div><p>Sorry, I re-read your question and realised I used (2) as my
proposed solution, why do you think this is a no no? If a mediator
deals with a single VO, what is the issue with it looping through a
list of them?</p>
<p>You could loop through the list in the command and dispatch
separate "this thing has been created" events rather than a single
"a list of things has been created" event, I guess.</p></div>stuarttag:robotlegs.tenderapp.com,2009-10-18:Comment/177026772012-07-31T07:45:09Z2012-07-31T07:45:09ZCreating Views from Model / Service VO's<div><p>I agree with Stu. Why would it be a no-no to loop through the VO
list in the mediator, but is it ok to do so in the view?<br>
Loop through the list in the mediator and pass the values to the
view which in turn creates the appropriate view objects.</p>
<p>That said, I <em>do</em> pass VO's to the view too, if two
conditions are met: the view represents the VO data fully and the
VO's are truly read-only.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/177026772012-07-31T11:29:30Z2012-07-31T11:29:31ZCreating Views from Model / Service VO's<div><p>That is after all the whole point of VOs being immutable,
no?</p></div>wagster