[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Interface coding by contract design and dependency injection

PerfectDayToChaseTornados

1/29/2007 6:44:00 PM

Hi All,

I am a Java developer of many years & just starting to get into Ruby (&
really enjoying it!). However I am used to 'coding by contract' using
interfaces. This is especially great when using dependency injection
(usually via Spring). It makes testing very easy, as 'mocks' can be written
simply & then plugged in. I know that there isn't an equvalent for an
interface in Ruby, but is there a pattern which would typically be used? I
was wondering whether to create Modules in place of my interfaces & provide
them with methods which throw Exceptions, thus forcing them to be overrriden
in the classes that include them? Also how does one manage dependency
injection in Ruby? Is there a good framework/library/pattern typically used
for this, or are there good 'Ruby reasons' not to use DI?

Many thanks

--
pdtct


7 Answers

Phillip Gawlowski

1/29/2007 8:28:00 PM

0

SonOfLilit wrote:
> Thee third google result for "dependency injection" is ruby-specific.

For me, it's a German Wikipedia article on DI.

http://de.wikipedia.org/wiki/Dependency...

- Phill

Paulo Köch

1/29/2007 10:13:00 PM

0

Did you mean http://onestepback.org/index.cgi/...
DependencyInjectionInRuby.rdoc ?

Paulo Jorge Duarte Köch
paulo.koch@gmail.com



Olivier

1/29/2007 11:24:00 PM

0

Hi,

I'm really new to dependency injection in general, but I hope I can help,
though. I am aware of two libraries for what you want to do. Copland, first,
is an Inversion of Control (IoC) container, based on the Hivemind IoC
container for java.
As you said, there is no interface in Ruby, so Interface based injection is
not supported. However, Type 2 IoC (Setter Injection) and type 3 IoC
(Constructor Injection) are supported.
The second is Needle, which is a Dependency Injection container. I don't know
much about it, except it supports a Service Locator mechanism.

By the way, the documentations are great for both ! Read them both and make
your choice !

http://needle.ruby...
http://copland.ruby...

--
Olivier Renaud

Le lundi 29 janvier 2007 19:45, PerfectDayToChaseTornados a écrit :
> Hi All,
>
> I am a Java developer of many years & just starting to get into Ruby (&
> really enjoying it!). However I am used to 'coding by contract' using
> interfaces. This is especially great when using dependency injection
> (usually via Spring). It makes testing very easy, as 'mocks' can be written
> simply & then plugged in. I know that there isn't an equvalent for an
> interface in Ruby, but is there a pattern which would typically be used? I
> was wondering whether to create Modules in place of my interfaces & provide
> them with methods which throw Exceptions, thus forcing them to be
> overrriden in the classes that include them? Also how does one manage
> dependency injection in Ruby? Is there a good framework/library/pattern
> typically used for this, or are there good 'Ruby reasons' not to use DI?
>
> Many thanks

PerfectDayToChaseTornados

1/30/2007 7:51:00 PM

0

Thanks Guys,

I'll check out Copland & Needle, anyone have any experience with either of
these with Rails?
--
pdtct


Phillip Gawlowski

1/30/2007 8:38:00 PM

0

Paulo Köch wrote:
> Did you mean
> http://onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionI... ?
>
> Paulo Jorge Duarte Köch
> paulo.koch@gmail.com

That didn't show up for me. Google results are depending on which data
center you catch, so just saying "google, and result #X will be
relevant" is a questionable technique to answer a question.

--
Over by the window lie the raiment and the weapons
That we need to take into this world today
Armoured by opinion, with statistic and schoolboy's charm
We take our place amongst the rank and file

Skyclad - A Survival Campaign

Larry in AZ

7/9/2007 6:44:00 PM

0

Waiving the right to remain silent, "What, Me Worry?" <__@____.___> said:

> "Larry in AZ" <usenet2@DE.LETE.THISljvideo.com> wrote in message
> news:Xns9967A9F643B06thefrogprince@69.28.173.184...
>> Waiving the right to remain silent, Roedy Green
>> <see_website@mindprod.com.invalid> said:
>>
>>> I could not feel good sitting in one.
>>
>> Ride a camel then...
>
> WTF is that supposed to mean, genius?

Would another language help you..?

--
Larry J. - Remove spamtrap in ALLCAPS to e-mail

"A lack of common sense is now considered a disability,
with all the privileges that this entails."

Coffee in Madrid

7/10/2007 8:16:00 PM

0

In article <Xns99687729E7F86thefrogprince@69.28.173.184>,
Larry in AZ <usenet2@DE.LETE.THISljvideo.com> wrote:

> Waiving the right to remain silent, "What, Me Worry?" <__@____.___> said:
>
> > "Larry in AZ" <usenet2@DE.LETE.THISljvideo.com> wrote in message
> > news:Xns9967A9F643B06thefrogprince@69.28.173.184...
> >> Waiving the right to remain silent, Roedy Green
> >> <see_website@mindprod.com.invalid> said:
> >>
> >>> I could not feel good sitting in one.
> >>
> >> Ride a camel then...
> >
> > WTF is that supposed to mean, genius?
>
> Would another language help you..?

I think he meant the "Sopwith Camel"... the Repubs prefer the old days
when the sun revolved around the earth.





Coffee in Airports