From: Joel VanderWerf Date: 2007-06-09T07:29:39+09:00 Subject: Re: Disadvantages of Dependency Inversion? Peter Booth wrote: > Given this, I'd say the drawbacks of DI are: > > uncertain value proposition > less explicit than the ServiceLocater pattern and thus harder to > debug/comprehend > not a fit for Ruby > canonical implementation (Spring) is a bit fat and overcomplex > other Java implementations are sparsely documented and have uncertain > viability > not pragmatic It's pretty easy to build a lightweight DI framework in ruby, taking advantage dynamic language features like method_missing.[1] But I rarely find the need to use it, even in relatively complex programs. However, ruby has some DI-like idioms that are very useful, with no need for a framework. A somewhat imaginary variant on a very common example: class Foo # map host to addr def addr_map @addr_map ||= {} end def session @session ||= Hash.new do |hsh,host| hsh[host] = Session.new(addr_map[host]) end end def send_to_host(msg, host) session[host].send(msg) end end [1] For example: http://raa.ruby-lang.org/project/mindi/ -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407