tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/214-why-create-the-interface-icommandmapRobotlegs: Discussion 2018-10-18T16:35:14Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/22120182010-07-09T11:49:21Z2010-07-09T11:49:21ZWhy create the interface ICommandMap?<div><p>2 main reasons spring to mind:</p>
<p>1) There are variations on CommandMap in utilities and
extensions which can implement ICommandMap.</p>
<p>2) Generally it's better to code to an interface rather than a
concrete implementation.</p>
<p>Personally I create interfaces for all my models and services,
whether or not I ever intend to have more than one class implement
that interface.</p>
<p>Firstly this provides a very clean 'signature' that you can look
at, and think about, to determine how the class behaves without
being distracted by how it does it.</p>
<p>Secondly it future proofs your coding and testing process
against deciding that you do need a concrete variant in the
future.</p>
<p>Thirdly, if you're doing test driven development, it's possible
to mock an interface (automagically generate a class that pretends
to implement that interface) and thus test a class that uses that
interface before you've written the concrete implementation of
it.<br></p>
<p>Mocking an interface frees you to order your workflow to suit
yourself and the problem in hand, rather than having to always
build your dependencies before you can build the dependent classes.
It also allows you to do much more isolated testing.</p>
<p>The first reason alone is good enough for me, the second is a
bonus, and the third is something I find myself benefitting from
much more frequently than I would have imagined before I got to
grips with mocking.</p>
<p>Shaun & Joel & co may have further reasons too!</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/22120182010-07-09T13:31:35Z2010-07-09T13:31:35ZWhy create the interface ICommandMap?<div><p>Stray has already mentioned all the reasons for using interfaces
even<br>
if there's just one implementation.</p>
<p>More generally, Robotlegs is roughly split into three parts:</p>
<ul>
<li>
<p>The core, consisting solely of interfaces that make up the
structure of the framework<br>
(<a href=
"http://github.com/robotlegs/robotlegs-framework/tree/master/src/org/robotlegs/core/">http://github.com/robotlegs/robotlegs-framework/tree/master/src/org...</a>)
In an important sense, these interfaces really <em>are</em> the
framework.<br>
Everything else is a mere implementation that could be switched
out<br>
entirely or in parts.</p>
</li>
<li>
<p>The base, which is a boiled-down, no-frills implementation of
said core (<a href=
"http://github.com/robotlegs/robotlegs-framework/tree/master/src/org/robotlegs/base/">http://github.com/robotlegs/robotlegs-framework/tree/master/src/org...</a>)<br>
In theory, this is enough of an implementation to actually work
with<br>
Robotlegs, although in practice, doing so would be so inconvenient
as<br>
to be silly. Instead, everyone working with Robotlegs does so with
a<br>
more fleshed-out implementation, such as the one to be found in</p>
</li>
<li>
<p>mvcs, which is a complete, convenient implementation of the
entire framework (<a href=
"http://github.com/robotlegs/robotlegs-framework/tree/master/src/org/robotlegs/mvcs/">http://github.com/robotlegs/robotlegs-framework/tree/master/src/org...</a>)<br>
I guess most people work with this implementation and don't
realize<br>
that it's just the most obvious, but by no means only way of
using<br>
Robotlegs. Some advanced users have modified this implementation
or<br>
built their own one from scratch or facilitating the base<br>
implementation described above.</p>
</li>
</ul></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/22120182010-07-09T13:43:29Z2010-07-09T13:43:29ZWhy create the interface ICommandMap?<div><p>Thanks for that Til -</p>
<p>I often forget that the mvcs implementation is in effect
actually the robot-trousers that robotlegs likes to wear.</p>
<p>Making this clear to users does make hacking that layer more
comfortable and less terrifying - you're not operating on the legs
themselves, you're just doing nips and tucks on the trousers.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/22120182010-07-09T13:48:46Z2010-07-09T13:48:46ZWhy create the interface ICommandMap?<div><p>That's exactly right - and a great metaphor, I think!</p></div>Till Schneidereittag:robotlegs.tenderapp.com,2009-10-18:Comment/22120182010-07-09T14:14:35Z2010-07-09T14:14:35ZWhy create the interface ICommandMap?<div><p>looks like im standing on the shoulders of giants here :)</p>
<p>thanks guys</p></div>Nikos tag:robotlegs.tenderapp.com,2009-10-18:Comment/22120182010-07-09T17:59:24Z2010-07-09T17:59:25ZWhy create the interface ICommandMap?<div><p>Also I imagine that it when it comes to injection you really
want to inject to an interface.</p>
<p>[Inject] public var commandMap:ICommandMap;</p>
<p>is WAY preferable to:</p>
<p>[Inject] public var commandMap:CommandMap;<br></p></div>neil manuelltag:robotlegs.tenderapp.com,2009-10-18:Comment/22120182010-07-10T13:21:27Z2010-07-10T13:21:27ZWhy create the interface ICommandMap?<div><p>true, that does give you some flexability</p></div>Nikos