Interface coding by contract design and dependency injection

Discussion in 'Ruby' started by PerfectDayToChaseTornados, Jan 29, 2007.

  1. 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
    PerfectDayToChaseTornados, Jan 29, 2007
    #1
    1. Advertising

  2. PerfectDayToChaseTornados

    Guest

    , Jan 29, 2007
    #2
    1. Advertising

  3. PerfectDayToChaseTornados

    Paulo Köch Guest

    Paulo Köch, Jan 29, 2007
    #3
  4. PerfectDayToChaseTornados

    Olivier Guest

    Hi,

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

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

    http://needle.rubyforge.org/
    http://copland.rubyforge.org/

    =2D-
    Olivier Renaud

    Le lundi 29 janvier 2007 19:45, PerfectDayToChaseTornados a =E9crit=A0:
    > 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 writt=

    en
    > 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 & provi=

    de
    > 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
    Olivier, Jan 29, 2007
    #4
  5. Thanks Guys,

    I'll check out Copland & Needle, anyone have any experience with either of
    these with Rails?
    --
    pdtct
    PerfectDayToChaseTornados, Jan 30, 2007
    #5
  6. PerfectDayToChaseTornados

    Guest

    Paulo Köch wrote:
    > Did you mean
    > http://onestepback.org/index.cgi/Tech/Ruby/DependencyInjectionInRuby.rdoc ?
    >
    > Paulo Jorge Duarte Köch
    >


    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
    , Jan 30, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=

    How to build a dependency injection framework by myself?

    =?iso-8859-1?B?bW9vcJk=?=, Aug 24, 2006, in forum: Java
    Replies:
    4
    Views:
    392
    PerfectDayToChaseTornados
    Aug 24, 2006
  2. Michael Feathers

    Dependency Injection in C++

    Michael Feathers, Oct 11, 2006, in forum: C++
    Replies:
    5
    Views:
    7,388
    F.J.K.
    Oct 13, 2006
  3. Anonieko

    What is Dependency Injection?

    Anonieko, Oct 14, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    297
    Michael Nemtsev, MVP
    Oct 14, 2007
  4. Danno
    Replies:
    12
    Views:
    690
    Ke Jin
    Apr 10, 2008
  5. Tomer
    Replies:
    14
    Views:
    284
    Arne Vajhøj
    Jan 5, 2013
Loading...

Share This Page