Java
The Java programming language













Subscribe to "Java" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
 

 

Wednesday, June 16, 2004
 

I'm hearing and reading more and more about Inversion of Control (IoC) and dependency injection. The latter is basically the idea of programming only to interfaces, and not knarling up your code with factories to get concrete implementations of those, rather letting something outside of an object "inject" the implementations, prior to them being required. This injection can happen either through setter methods, or constructors. So its inverting control, hence IoC. The container controls which implementations an object gets, the object (class) is developed against interfaces. Wiring the whole lot up is an exercise for the container, based on some sort of (usually non-code based) configuration, like an XML file.

IoC containers that are on my radar include Spring (not just a container btw), PicoContainer and HiveMind.

Its a bit weird at first, but once you get used to it, the benefits become clear: code that is easier to evolve, everything is pluggable, and unit testing is a doddle - you can isolate units of code at a very granular level, stub everything else with test implementations (like your junit TestCase can implement all of a test targets dependencies and feed it exactly what it needs to prove some bit of functionality).


2:56:04 PM    comment []


Click here to visit the Radio UserLand website. © Copyright 2006 David Black.
Last update: 6/13/2006; 1:22:43 PM.
This theme is based on the SoundWaves (blue) Manila theme.
June 2004
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
Jan   Aug