<< RSS Support In Thunderbird 0.8 | Home | Google Knows >>

Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

Reading through the new JDK 5.0 documentation, I found this piece of gem:

In DOM level 3, additional methods were defined in the following interfaces:

  • Attr
  • Document
  • DOMImplementation
  • Element
  • Entity
  • Node
  • Text

The added methods only affect applications that implement the interfaces directly, and only then when the application is recompiled. Applications that use the factory methods to obtain implementation classes for these interfaces will have no problems.

After years of yelling at people "Don't ever change your interfaces, you will break other peoples code," I feel pretty annoyed by this.

True, 5.0 is a compatibility breaking upgrade (if you have ever written code like Enumeration enum = myVector.elements(); back in the 1.1.4 days), but adding public methods to interfaces is a crime much more severe.

Even in the old 1.1.x days people know to introduce new and improved interfaces with a different name: LayoutManager2 vs. LayoutManager.

On a practical level, this means that even after I have upgraded to JDK 5.0, I have to keep a copy of JDK 1.4.2_05 around just to compile old code that implements the narrower interfaces, until everybody in the world have patched their code for 5.0!



Re: Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

These changes only impact you if you've implemented a DOM parser, right?

Re: Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

This follows the spec for binary compatible changes which has been in the Java language spec since ... THE VERY BEGINNING. And calling an interface LayoutManager2 is, and always has been, completely retarded. Do you not know how to name classes or interfaces properly?

Re: Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

Or if you've implemented one of the DOM interfaces that are widened.

Re: Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

Anonymous is right. The changes are binary compatible, even though not source compatible. I shouldn't have been so loud.

Re: Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

Yes its stupid to do this. But it isn't a big deal. Your code will work under JDK 1.5 without recompilation and 100% compatability will remain EVEN IF you implemented the old versions of the interfaces. When you will try to invoke a missing method you will get an exception. The JDBC guys did this with every version and it used to piss me off as well, but its nothing new and its not Sun's fault: JDBC and DOM are developed by 3rd parties no Sun!

Re: Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

Personally, I look forward to the day when Sun "cleans up" Java. They could remove all deprecated methods, remove Vector/HashTable, etc...

Re: Whatever Happened to "Never Change Your Interfaces" (JDK 5.0 Horrors)

This isn't the first time. JDBC has changed every release.

Add a comment Send a TrackBack