Dependency Injection

You hear dependency injection often mentioned in the context of unit-testing as way to break dependencies and providing seams for testing (a term that I think Michael Feathers coined in Working Effectively with Legacy Code).

I actually learned dependency injection years ago when working on a project where the requirements where constantly changing. As a result, what our product needed to do was changing pretty rapidly as well. Dependency injection allowed us to map out our interfaces, and wire the pieces together as we saw fit. Using the same basic components, we were able to adapt to the changing requirements simply by rewiring the flow of data. It was a remarkable technique when I learned it–which was through hard knocks rather than Design Patterns and the like.

Nonetheless, dependency injection is useful outside the context of unit-testing. Unit-testing just happens to be a common use for it. Make sure to take a look at the Wikipedia entry, as it includes a number of links to dependency injection frameworks that might be useful to your project… including Spring For Python!