Dependency Injection

| 0 Comments

Jeremy D. Miller writes about The Dependency Injection Pattern; or what I've tended to call "Parameterise from above". He covers the various ways you can inject a dependency into a class rather than having the knowledge of the dependency hard wired into the class itself. I tend to favour the constructor injection pattern myself; it's all about breaking concrete coupling with interfaces and then allowing the creator of the object to specify the concrete type used by the object.

As Jeremy says, it's not just for testing; it leads to much more flexible software. It's worth following the link from Jeremy's post to Martin Fowler's "Inversion Of Control and the Dependency Injection pattern" as this is definitive coverage of the technique.

Leave a comment