Does the ServiceLocator pattern have life after EJB3.0?

Brandon Werner has an interesting article on JavaLobby.com looking at how typically the ServiceLocator pattern has been implemented prior to EJB3.0, and whether or not it will be needed with EJB3.0.

The ServiceLocator has been called a ‘compensating pattern’, one of a collection of patterns from the J2EE Core Patterns book by Sun that are viewed by many as patterns that attempt to negate some of the disadvantages and complexities of dealing with J2EE. They are know as ‘compensating’, because the general opinion has been if EJBs were designed right in the first place, we wouldn’t need the majority of these patterns in the first place.

Werner shows in his article how the ServiceLocator pattern is used to hide the complexities of looking up JNDI resources, and compares to how this is implemented in EJB3.0 using annotations and Dependency Injection. The EJB3.0 approach is much simpler and cleaner, and yes, in this case, we would no longer to use an approach like the ServiceLocator.

Coding Blind?

I’ve noticed over the last couple of years that quite a few Java developers manage to develop on their workstations without even having a local copy of the Javadoc for the core language API, and in most cases the same is also true for any thrid party API being used. I’ll be working with them on a problem and say, ‘bring up the API Javadoc and let’s see if there’s a method we’re looking for’ and they’ll look at me blankly. ‘Ok, go out to the Sun site and we’ll browse it online from there’.

At that point I am blown away when they don’t even know how to find the API on the java.sun.com site itself – the home of Java.

Quite how some of these developers manage to get anything done is beyond me. And how they ever learn anything new is also a mystery. There used to be a time in the ‘good old days’ of Java in late 90s when everyone I worked with had a well worn copy of ‘Java in a Nutshell’ on their desk. Why? Because it has a printed copy of the Javadoc for all the core classes and methods – not everyone likes to browse stuff online. But second to that, or in addition, developers would also have a downloaded copy of the J2SDK Documentation on their machine, with a bookmark straight into the API. In some cases (I know I do) they would set the home page in their browser straight into the Javadoc.

To be a good craftsman you have to know your tools. This is one area where for some reason one of the most basic and most useful tools is often overlooked. If you are a Java developer and don’t have a copy of the J2SDK or Java5.0 documentation on your machine, go and download it now, and maybe even take a read…