.java

musings on java and object oriented software development

Thursday, December 08, 2005

Ruby Array vs. Java List, Human Interface etc.

I'm coming into the discussion about Martin Fowler's post about Ruby Array vs. Java List a bit late I guess, and this post and follow up on Cafe au Lait because I thought it was obvious that the discussion was an irrellevent apples and oranges comparison:

Array is a class, List is an interface

Obviously these are seperate concepts, one cannot go adding new methods to an interface without breaking all the implementors of said interface. Also, the burden of implementing a large amount of methods in an interface would be too great.

A different way

There is a solution however, have an facade class to represent the "human interface" in Fowler's parlance and an interface that represents the raw access to the underlying structure. Most people would only deal with the facade, but implementors of data structures would design to the interface.

For that to work the List interface would need to be richer, with methods that hint at the most efficient way to traverse the underlying structure (for instance it's not so efficient to randomly access a LinkedList). This is kind of like the spiinterfaces in the java.security package.

0 Comments:

Post a Comment

<< Home