News for hackers. Stuff that matters.
Re:Dependency Injection is a Virtue by Xylakant on Monday January 07, 2013 @04:50AM (#5020236)
Your example is not DI. Your argument is in general sound, but it's tangential to the problem of DI. Your time object needs to be created at some point. DI would allow you to swap out the implementation of the Time class at that point.

In general, the time example is stupid. A better example is maybe that you have an app that wants to make http calls. Depending on the interpreter and the os you might want to switch the http library. Net/HTTP is a solid default that runs everywhere, but there are faster alternatives if you're on MRI only. In java, you need DI to solve this problem. In ruby, you don't.

There are no comments on this comment yet.