Friday, 2 January 2015

Dependency injection by Spring

In a previous post I stated that classes must implement interfaces, and interaction between classes will only occur through their respective interfaces. The idea behind this decision is quite simple: in order to facilitate reuse and testing principles, Java classes should be as independent as possible from other classes. Classes that have no hard dependencies - they don't reference any specific class instance - can be used and tested in isolation, primarily through mocking strategies. This program pattern has been extensively defined and comes under the name of dependency injection, or inversion of control (IoC).

Spring is a framework that provides developers with a comprehensive list of tools for the implementation of dependency injection in Java projects. Spring is massive. Spring will make coffee, if properly instructed, and that's the main reason why I adopted Spring. Oh, and also because I used Spring when I was at uni and other options (Guice, Pico) are not very popular, yet. Must be a reason why, after 8 years since I left uni, Spring is still that popular.

I'll be using Spring 3.1.0 libraries and a bunch of dependency libraries such as commons-logging and spring-security. A full list of libraries used in this project is available under the /lib/ folder.

No comments:

Post a Comment