Friday, August 20

Constructor Dependency Injection In Java

I have written a draft article on Constructor Dependency Injection In Java.

Your comments would be appreciated.

1 Comments:

Anonymous Anonymous said...

Broken link :(

Ben, please post you paper here.

I like the fundamental concept of inversion of control, but leaving everything to set methods sounds like risky business to me.

I believe constructors should be used for what they were intended for. Creating a fully stateful object or it throws an exception and a reference to it never exists. There are problems with constructor configuration as its not as flexible as set methods and non-interfacable. But I prefer this to the problems of incomplete objects and initialization processes which are made fragile by setting dependencies in random order (or not at all).

Sometimes it's not possible to supply everything at construction time (complicated by the fact constructors can't touch members before super methods are called). But this is the exception to the rule.

If one or a few constructors don't satisfy all requirements, meaning lots of set methods are needed, perhaps the object is too complicated to start with and requires delegation.

1:06 pm  

Post a Comment

<< Home