tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/920-are-model-classes-uselessRobotlegs: Discussion 2012-06-28T09:20:44Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/162068382012-05-24T12:19:41Z2012-05-24T12:19:42ZAre Model classes useless ?<div><p>Hello,</p>
<p>I've been following some examples about how to use Models in a
MVCS project and as I was progressing in my project I realised that
I couldn't see any benefit of using my Models the way I use them.
So, first of all, I'm wondering if I'm using them right and
secondly, if that's the case, then can somebody explain what's the
point? Because I don't get it :)</p>
<p>Here is what I do:</p>
<p>A service receives remote data and transfers it to the
model:</p>
<pre>
<code>protected function getAllSBServersSuccess(e:ResultEvent):void{
var DBServers:ArrayCollection = new ArrayCollection(e.result as Array);
dbServerModel.setAllDBServers(DBServers);
}</code>
</pre>
<p>Then in the model, I do a copy of the data and dispatch an event
to transfert the result to my Mediators:</p>
<pre>
<code>public function setAllDBServers(DBServerList:ArrayCollection):void{
this.DBServerList.removeAll();
for each(var dbServer:DBServer in DBServerList){
this.DBServerList.addItem(dbServer);
}
dispatch(new DBServerEvent(DBServerEvent.GET_ALL_DBSERVERS_LOADED, this.DBServerList));
}</code>
</pre>
<p>Then in my Mediators, I use the result object sent along with
event.</p>
<p>So my question is, why not dispatching the event directly in the
service instead of using a Model class, doing a copy and then
dispatching... Because as it is here I really don't see the point
except if you like to add classes and have an even more confusing
code :)</p>
<p>I've been using the following diagram to help me and I think the
part I don't quite understand is the step 5a:<br>
<img src=
"http://m.migliori.free.fr/captures/MVCRobotLegsQuestion.jpg" alt=
"Image Name"></p>
<p>Thank you for your help</p></div>Migstag:robotlegs.tenderapp.com,2009-10-18:Comment/162068382012-05-24T12:32:30Z2012-05-24T12:32:30ZAre Model classes useless ?<div><p>your model should store the state of your application, services
are responsible for fetching/sending data which may also be stored
in a model. You can combine the two but keeping them separate
should in theory make for less confusing code (your model dealing
purely with manipulating data without having to worry about how and
where it comes from), and also allow you to swap out different
services without having to touch your model. A service may well
also be used by multiple models so again, separating out the
responsibilities gives you far more flexibility.</p></div>matttag:robotlegs.tenderapp.com,2009-10-18:Comment/162068382012-05-24T13:03:19Z2012-05-24T13:03:20ZAre Model classes useless ?<div><p>Thank you matt for your answer,</p>
<p>However my issue is not really that I'm trying to put everything
in the service, it's more that I feel like I don't need the model
at all whether it's merged in the service or seperated.</p>
<p>I'm using ampfphp, this means that the data that I receive from
my service is already an instanciated VO. This VO represents in a
way my model and I can transfer it to my view without the need of a
Model class in between. At least that's how it feels in this
scenario...</p></div>Migstag:robotlegs.tenderapp.com,2009-10-18:Comment/162068382012-05-24T13:52:53Z2012-05-24T13:52:53ZAre Model classes useless ?<div><p>Hi Migs,</p>
<p>I instinctively agree with Matt - and from a 'testing' and
'knowing the state of the world' point of view, models are useful -
not least because for most of us they feel like a better fit with
our brain's understanding of the app.</p>
<p>However - there are many styles of programming that are
essentially 'stateless' - in which you would take the approach
you're floating, where the values get passed along to the
interested parties without being stored in a model along the
way.</p>
<p>The two approaches each have merits.</p>
<p>In fact, we frequently skip the model when dispatching results
from services - any message about progress, errors and so on is
likely to be sent right from the service out to the view or logger
without being stored in a model.</p>
<p>On the other hand, data that might want to be restored, have
undo or history, be retained for checking whether there are
actually changes to save, be used for logic or flow, and so on,
clearly needs a model.</p>
<p>I think the question you're really asking is "in the context of
my app, is this a model, or is it just a message?". Your model
still exists - it's just outside of the app, sitting on a server
somewhere. You've abstracted the M layer of your MVCS entirely into
the backend. That's ok - it's just as valid as when we abstract any
other layer.</p>
<p>The AWESOME thing about Robotlegs is that you can develop
<em>without</em> the model, and then, if you find that you
<em>do</em> need a model, you can just add a command that also
picks up the values and stores them in a model. Changing your model
/ no model decision with Robotlegs should be trivial.</p>
<p>So - high fives to MVCS for allowing a layer to be included /
removed within one technical domain as required.</p>
<p>hth - great Q by the way.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/162068382012-05-24T13:53:21Z2012-05-24T13:53:21ZAre Model classes useless ?<div><p>in that case, if it feels right - i would say it probably is
right : )</p></div>matttag:robotlegs.tenderapp.com,2009-10-18:Comment/162068382012-05-24T14:26:32Z2012-05-24T14:26:33ZAre Model classes useless ?<div><p>Thank you Stray. That's exactly the kind of answer I needed
:)</p>
<p>I love the fact that I can use models only when I need them. I
just hope that I will be able to tell my self "hey here I need a
model it feels right!". But you gave a few examples giving me a
rough idea so I should be alright.</p>
<p>Thx again, you rock ;)</p></div>Migs