tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/786-how-to-use-models-and-vosRobotlegs: Discussion 2018-10-18T16:35:35Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T20:45:44Z2012-01-12T20:45:45ZHow to use Models and VO's<div><p>Hi,</p>
<p>for example i have a book,<br>
every book have pages,<br>
every page have text + images.</p>
<p>Should i have BookModel instance + PageModel instance for every
PageView instance?<br>
Or just one BookModel and one PageModel instance? (But how then
PageModel will know on which page I'm asking, every method will
have pageIndex?)</p></div>Nangratag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T21:33:28Z2012-01-12T21:33:29ZHow to use Models and VO's<div><p>I think I would go with:</p>
<p>BookModel<br>
hold reference to a vector of pages.</p>
<p>PageVO<br>
holds the data text and ref to images that get passed to each
page-View upon request</p></div>Pierre Laveklinttag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T21:34:09Z2012-01-12T21:34:10ZHow to use Models and VO's<div><pre>
<code>PageModel{
public function getImages():Array
{
// How this model will know of witch page images i'm asking?
}
}</code>
</pre></div>Nangratag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T21:35:41Z2012-01-12T21:35:41ZHow to use Models and VO's<div><p>Pierre Laveklint</p>
<p>But VO shouldn't have any logic inside. So how can I for example
add a new Image and dispatch event about this.</p></div>Nangratag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T21:51:10Z2012-01-12T21:51:11ZHow to use Models and VO's<div><p>Correct, a VO is just a value object and should not handle any
logic.</p>
<p>In BookModel you can set up a pageIndex which matches current
page-id.</p>
<p>BookModel</p>
<pre>
<code>_pageIndex:int = 0; // make getter + setter
public function getCurrentPage():PageVO
{
return pages[pageIndex];
}</code>
</pre>
<p>PageVO</p>
<pre>
<code>public var textContent:String;
public var imagePath:String</code>
</pre>
<p>Make sense?</p></div>Pierre Laveklinttag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T21:57:09Z2012-01-12T21:57:11ZHow to use Models and VO's<div><p>But how to get the 5th image from the 4th page</p>
<p><code>bookModel.getCurrentPage(). // And what now? I got VO
which don't have method to get image by index</code></p>
<p>So should I create PageModel? But one for every VO? That don't
make sense:/</p></div>Nangratag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T22:12:36Z2012-01-12T22:12:37ZHow to use Models and VO's<div><p>You can set the image variable to a vector/array of strings
(paths to images).<br>
When you received the PageVO of your choice you can grab the image
you want.</p>
<pre>
<code>var pageVO = model.getCurrentPage()
trace(pageVO.images[4])</code>
</pre>
<p>if you need to add/remove pictures to a page during runtime the
I would consider making a PageModel as well.</p></div>Pierre Laveklinttag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T22:17:40Z2012-01-12T22:17:41ZHow to use Models and VO's<div><p>I need more complicated methods than just getImage, this is just
example.</p>
<p>But sa You said, making PageModel... How PageModel would know
about which PageVO I am asking him.</p>
<p>BookModel is easy becouse i have just one instance of Book, but
pages are unlimited and just one PageModel :|</p>
<p>Can You give me a short example with BookModel and PageModel
where BookModel return a page instance, and a PageModel return any
image from page which was get from BookModel?</p></div>Nangratag:robotlegs.tenderapp.com,2009-10-18:Comment/128661392012-01-12T22:27:28Z2012-01-12T22:27:29ZHow to use Models and VO's<div><p>Sorry, typing on my iPhone and I just posted a a quite long
answer but seems it didn't make it in here for some reason. I have
to run now, will see if I get the time tomorrow to set up an
example.</p></div>Pierre Laveklint