Service Locator vs. Dependency Injection

June 25, 2007 | In Java, Javaone | No Comments

Last year at Javaone I attended a session on API design held by some Netbeans developers. I remember I thought they used a strange definition on Dependency Injection (DI). Now when I see this years session on the same subject (Modular Programming with the NetBeans Platform, TS-3742) I still think it’s strange:

not_di.png

DI should use the “Hollywood Principle” - don’t call us, we’ll call you. Your Java class should get its dependencies set or wired in the constructor. It should not call out to its environment to resolve them.

The code sample above is using the Service Loader (SL) feature in Java 6. You specify somewhere under META-INF in the jar file what interface you implement. Then the client code can ask for an implementation of this interface in runtime. SL is “pull”, DI is “push”.

There is nothing wrong with this style, but it is not DI. It’s hard enough keeping up with the different idioms and patterns so please use well established names for things.

Swedish article on Open Source

June 13, 2007 | In Uncategorized | No Comments

I tried to get an article on how to open source a software project published in a Swedish magazine. They didn’t want it so I published it on my blog instead. If you know Swedish here is the link:

PDF, 412 Kb.

What is Apple up to?

June 12, 2007 | In Uncategorized | No Comments

The WWDC keynote was thin. All those Apple engineers and this was the result?

Ok, I know that the iPhone probably requires a lot of resources. But it can’t have sucked all power from the R&D in Apple Inc?

My guess is that they have something big cooking. Maybe for MacWorld?

Entries and comments feeds. Valid XHTML and CSS. ^Top^