tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/699-static-constantsRobotlegs: Discussion 2018-10-18T16:35:33Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/107790802011-10-21T21:34:02Z2011-10-21T21:34:02ZStatic constants<div><p>Hi Rob,</p>
<p>when you inject against an interface you're building your
classes to use a contract, but without binding them to a specific
implementation of that contract.</p>
<p>For example - if you inject an IUserAuthorisationService then
you can implement that as a RemoteUserAuthorisationService and a
TestUserAuthorisationService - allowing you to have your app
'authorise' a user before the back end service is actually
available.</p>
<p>That's one of the main tangible benefits anyway - being able to
compile your app in a state that makes it quick and easy to test or
for a client to get straight to the part that you want them to give
you responses to.</p>
<p>On a higher level, when you build against an interface you're
freed of any thoughts about "how" stuff gets done - and you can
think in terms of that contract more cleanly.</p>
<p>I wouldn't map those two VOs as individual values. I'd be more
inclined to have a ColourSwatchVO (with an interface) and have
properties .blue and .green on that item.</p>
<p>I'm slightly worried about the idea of injecting colours
though... perhaps a bit of info on your use case would reassure me?
If you're doing skinning or similar then there are neater ways to
achieve this.</p>
<p>In short - you are right that "I have to inject X all over the
place" is a code smell!</p>
<p>hth (sorry about your question being stuck in spam)</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/107790802011-10-21T22:13:45Z2011-10-21T22:13:49ZStatic constants<div><p>Thanks very much for your response, Stray (and thanks for
pulling my post out of spam).</p>
<p>My use case is, in fact, skinning. I was planning to provide a
series of small buttons along the bottom of the application that
allow the user to change the color theme. It will be pretty simple:
Click the blue button and a predominantly blue background image is
displayed, while other visual elements (e.g. Sprites) change to a
shade of blue. Click the red button...same idea.</p>
<p>When the button mediators handle the click events, I was
originally thinking of having them dispatch a custom event
(ThemeChangeEvent) into the context that carries a property for
whatever the new color should be. I thought a command could handle
this custom event and make a call to a service that loads the
appropriate background image. Since these colors will never change,
I thought maybe I should use static constants...then I thought
value objects...now after your post I'm not sure how best to handle
this.</p>
<p>Any suggestions based on my use case?</p>
<p>Thanks,<br>
Rob</p></div>rob.johansentag:robotlegs.tenderapp.com,2009-10-18:Comment/107790802011-10-21T22:47:14Z2011-10-21T22:47:14ZStatic constants<div><p>Hi Rob,</p>
<p>I'd make a SkinningFactory class (that implements an iFace) and
inject that into your mediators.</p>
<p>In onRegister, pass the instance of the view to the
SkinningFactory and have the factory do the magic by passing the
assets / colour parameters to the view.</p>
<p>You'll probably want to use the view class to look up in the
SkinningFactory what to actually give to the view. (And of course
you'll inject the SkinningFactory against ISkinningFactory in your
view).</p>
<p>Then you can hold a list of the views that have been skinned
already (so that you don't do them twice if they come and go from
the stage).</p>
<p>When your mediators pick up the ThemeChangeEvent they can pass
their views to be skinned again (and you drop the cache on the
SkinningFactory when the colour changes, so that any view is 'fresh
meat' to be reskinned). And you'll have used a Command to update
the current theme that the SkinningFactory should use.</p>
<p>Does that make sense?</p>
<p>Basically you want to abstract this functionality into something
nice and separated.</p>
<p>I hope that makes sense? Of course there are a ton of other ways
to do it too but this is my preferred method - I've tried many and
this one keeps me sane!</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/107790802011-10-22T01:03:31Z2011-10-22T01:03:31ZStatic constants<div><p>That makes sense. Thanks for the help.</p></div>rob.johansen