tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/640-variables-by-referenceRobotlegs: Discussion 2013-04-28T10:18:36Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/94719082011-08-22T15:06:02Z2011-08-22T15:06:04ZVariables by reference<div><p>Hi,</p>
<p>I have a question for you clever thinkers out there regarding
the use of variables by reference. As I understand it, complex
objects are always passed on as reference in AS3. So if class B
modifies a value object passed to it by class A, then the
modification will affect the value object in class A as well as in
any other class that is storing it. It is almost as if the value
object is a singleton.</p>
<p>Do you utilize this behavior for your advantage?</p>
<p>I have an example from my own code to explain better. I have a
LocalizationModel that stores a LocalizationVO. This vo stores a
current language id and UI strings that have to be localized. I
pass this vo to any view that needs localized strings for buttons
and such. Then whenever the language is changed I have a command
modify the language id in LocalizationVO. Mediators can then
instruct their views to update all strings. In most examples I have
seen of similar logic, the language id would be sent along with the
request to update - but that seems redundant. The view already has
a reference to the vo that the command changed - so why send it -
or any info already in it again. The view can simply update all
strings according to the language id in it's referenced vo because
the change the command made are already there.</p>
<p>There must be a valid reason for coders not to use this
functionality. Maybe for readability?</p>
<p>Is it considered bad practice to utilize the fact that complex
objects are always passed as a reference?</p>
<p>Best</p></div>Samúel Jónassontag:robotlegs.tenderapp.com,2009-10-18:Comment/94719082011-08-23T16:49:03Z2011-08-23T16:49:03ZVariables by reference<div><p>VO members should be read-only. The reason why it should be
avoided to have writable VO members (and this is why I hate data
binding in flex too) is because it's really hard to maintain and
debug. If a value is changed incorrectly you'll spent a lot of time
finding out where exactly it goes wrong.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/94719082011-08-23T16:57:52Z2011-08-23T16:57:52ZVariables by reference<div><p>By the commonly-held definition, value objects are just value
containers<br>
passed along with messages, so they aren't meant to last.</p>
<p>I've personally always liked the idea of using variables by
reference<br>
instead of pass-along value objects. I'm not sure why, perhaps
because<br>
it might save memory (less object instantiation)?However, I think
in<br>
that case they'd be more "model-y" than "value object-y". That's
all<br>
just names of course. I've never actually gone so far as to try
building<br>
an app that way, so I can't say whether it would actually work
in<br>
practice. I think I'd certainly need to implement some sort of
data<br>
binding, by which I mean at least having a "change" event for
each<br>
property in the object so you can propagate value changes to the
screen.</p>
<p>Paul</p></div>Paul Robertsontag:robotlegs.tenderapp.com,2009-10-18:Comment/94719082011-08-24T21:27:29Z2011-08-24T21:27:29ZVariables by reference<div><p>Thank you for you thoughts on this.</p>
<p>I do understand the concerns about readability. But since I came
from PureMVC where my proxies usually stored all their data in
single "SmartVO" I have been creating my models in Robotlegs to
hold all their data in a single vo. The properties in them may be
simple values or "nested" vo's. So that vo "is a model" and I only
use commands to update their values. So for me readability is not
an issue.</p>
<p>But after reading your thoughts on this I do feel like I should
not be applying the PureMVC best practices to my models in
Robotlegs.</p>
<p>Best</p></div>Samúel Jónassontag:robotlegs.tenderapp.com,2009-10-18:Comment/94719082011-11-01T14:00:50Z2011-11-01T14:00:50ZVariables by reference<div><p>If you need more help with this, please feel free to re-open
this discussion. Please open new threads for new issues.<br>
Thanks!<br>
Ondina</p></div>Ondina D.F.