tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/1072-models-and-servicesRobotlegs: Discussion 2018-10-18T16:35:42Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/188699532012-09-19T20:03:41Z2012-09-19T20:03:43ZModels and Services<div><p>Looking at the RL book examples, it looks like injecting the
model into the service is an accepted practice.</p></div>John R. Nyquisttag:robotlegs.tenderapp.com,2009-10-18:Comment/188699532012-09-21T13:28:47Z2012-09-21T15:23:51ZModels and Services<div><p>Hi John,</p>
<blockquote>
<p>Looking at the RL book examples, it looks like injecting the
model into the service is an accepted practice.</p>
</blockquote>
<p>Of course!</p>
<p>In case you’re aiming for extreme decoupling and
separation of concerns, you won’t inject the model into the
service. Instead you inject it into the command triggered by the
event dispatched by the service when it’s done loading data.
The command will then access model’s API.<br>
Also, if you want a service to be generic, or if more than one
model should be populated with service’s results, then
it’s better if commands take care of updating the
model(s).</p>
<p>On a scale of 1 to 10, I’d give <a href=
"http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/http/mxml/HTTPService.html#includeExamplesSummary">
Adobe’s approach</a> a 1, and the following à la
Robotlegs MVCS a 10:</p>
<p>View -> ViewEvent (UI interaction) -> custom Event
->Mediator -> custom Event re-dispatched on a shared event
dispatcher -> Command -> Service’s API ->
ServiceEvent -> custom Event dispatched on a shared event
dispatcher -> Command->Model’s API-> custom Event
dispatched on a shared event dispatcher -> Mediator
->event’s payload-> View’s API</p>
<p>There are obviously other possible and valid combinations
between the two extremes.<br>
The level of decoupling, cohesion, dependency, or encapsulation of
classes in a project<br>
depends very much on the use case, on project’s requirements,
project type (game, enterprise, mobile), size of the project, team,
on personal preferences…<br>
In other words, the specificity of an individual project may
require an adaptation of, or deviation from the Best Practices. If
strictly following the Best Practices guidelines feels like
hammering square pegs into round holes, then either you’re
not familiar enough with the concepts yet, or it’s probably
time to find a compromise, a middle way that best suits your
project. Also, RL’s Best Practices revolve around MVCS, but
maybe your project would benefit more from adopting another design
patterns (say, MVP).</p>
<p>I’m saying all this because the Best Practices and/or some
of the answers on this forum may sound a bit restrictive or
prescriptive to someone new to rl. Or, on the contrary, many people
are surprised to see different approaches presented in form of
answers or demos, and don’t know what direction to take. I
think having more options to choose from is a good thing, even if
it’s a bit of a challenge for beginners.<br>
My advice is to get familiar with the best practices and the
extreme, “pure” MVCS scenarios first, while keeping in
mind that they are not the ‘Ultimate Answer’, and that
Robotlegs, as a framework, is really very flexible and permissive
:)</p>
<p>Cheers,<br>
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/188699532012-09-21T14:42:23Z2012-09-21T14:42:23ZModels and Services<div><p>I've been doing OO for a looong time, so I was building this
setup: View -> ViewEvent (UI interaction) -> custom Event
->Mediator -> custom Event re-dispatched on a shared event
dispatcher -> Command -> Service’s API ->
ServiceEvent -> custom Event dispatched on a shared event
dispatcher -> Command->Model’s API-> custom Event
dispatched on a shared event dispatcher -> Mediator
->event’s payload-> View’s API</p>
<p>That's when I thought I'd post the question, after which I saw
the book examples that coupled the model to the service. I agree
there are a lot of factors in deciding how pure you can (or want
to) go on each particular project. It's nice to hear how others are
working with RL.</p></div>John R. Nyquisttag:robotlegs.tenderapp.com,2009-10-18:Comment/188699532012-09-21T15:21:20Z2012-09-21T15:21:20ZModels and Services<div><blockquote>
<p>I've been doing OO for a looong time</p>
</blockquote>
<p>Cool! Then you’ll become an RL expert in no time:)</p>
<blockquote>
<p>It's nice to hear how others are working with RL.</p>
</blockquote>
<p>I agree. Have you seen the <a href=
"http://knowledge.robotlegs.org/discussions/resources/33-links-to-robotlegs-resources-examples-tutorials">
long list<br></a> of examples and tutorials written by different rl
users? A wide range of rl-coding styles.</p>
<p>If you don’t have any other questions or any other
comments to add, you can close the discussion. („Close the
discussion“ button on the right side of the page)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/188699532012-09-21T15:56:48Z2012-09-21T15:56:48ZModels and Services<div><p>I had not been to that page yet, thanks!</p></div>John R. Nyquist