tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/11475-inject-values-into-a-modelRobotlegs: Discussion 2014-08-25T17:31:07Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/337494242014-07-14T11:33:03Z2014-07-14T11:33:03ZInject values into a model?<div><p>Hi Dan,</p>
<p>First of all, injecting player1 and player2 like this wouldn't
work. To differentiate between the 2 you'd need named
injections:</p>
<pre>
<code>[Inject (name="somePlayer")]
public var player1:Player;
[Inject (name="anotherPlayer")]
public var player2:Player;</code>
</pre>
<p>Then, the question is, what is Player? A view class, another
model, a VO, something else?</p>
<p>It's hard to say if injecting Player into GameModel is a good or
a bad idea just from looking at the few lines of code. The use case
is not specific enough.</p>
<p>Injecting dependencies into a Model is not a bad thing per
se.</p>
<p>It depends on the role of the injected class: injecting Views,
Mediators, Services, or other mutually dependent Models into a
Model is not a recommended practice.<br>
But, it also depends on the specific use case and the overall
structure of the project. Question to ask: How is GameModel
'manipulating' the 2 instances of the Player class? What is the
role of the GameModel? Is it holding state, or is it manipulating
some data? Does injecting the Player class break encapsulation? Is
GameModel less reusable because of the Player dependency? Is it
harder to test the application because of Model's dependencies?</p>
<p>Or, is there an entity system/framework involved, where maybe
GameModel is not a "typical" robotlegs model?</p>
<p>You probably know more about the concrete use case, so you might
be right in thinking that injecting the Player into the GameModel
was problematic. Tell us more about the project or/and the way
you'd solve the Player problem, so that I, or anyone else, could
give you a more specific answer.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/337494242014-07-28T12:19:16Z2014-07-28T12:19:16ZInject values into a model?<div><p>I usually inject singleton signals into models, to avoid
injecting models into mediators.</p>
<p>but I inject them as setters to avoid future mistakes</p>
<p>[Inject] public function set signal(value:Signal):void{<br>
_signal = value; }</p></div>bojamunjetag:robotlegs.tenderapp.com,2009-10-18:Comment/337494242014-08-23T00:11:57Z2014-08-23T00:11:57ZInject values into a model?<div><p>Thanks for the comments and good questions. This was just an
informal open ended coding challenge to open up OO and design
pattern discussions.</p></div>dan