A Funny Java Flavoured Look at the World

Thursday, June 08, 2006

Joshua Bloch: A conversation about design

I read this interesting article about API Design and reuse from Joshua Bloch being interviewed by Bill Venners. The article is from 2002 but I think the points are still relevant today.

I have found that the Java developers I have worked with and including myself don't reuse much of their code. The problem usually occurs because the code written is often tightly coupled with the project they worked on to create it. I think Bloch makes good points stating

"Decomposition into subsystems is important, but as important is to have each subsystem be a well-designed, freestanding abstraction"

I think this is something that doesn't occur often enough. If people split the work into small self contained modules/components then these could be reused in other projects. I have found recently that I have been trying to make sure that my methods will have "only one reason to change" this sometimes means creating more methods but it creates methods that don't depend on too many variables or are tightly coupled with code you are currently writing. This also means that if I want to reuse these methods/classes then it should easy.

I often find that these changes happen when I am refactoring and trying to eradicate duplication. This article puts to words what I have been thinking about and trying to do whilst writing code recently. If you write code like this it is also a lot easier to write unit tests for. Writing unit tests can be a good guide, if you are struggling to write a unit test for some code then perhaps the code is doing to much.

I like this question

"Venners: You also claim in your book that thinking in terms of APIs tends to improve code quality. Could you clarify why you think that. "

I have been trying recently whilst trying to write smaller methods with one focus and then use the smaller methods in bigger methods etc. I have been trying to think of my code as a library or code. I have been trying to think about the code as an API, I suppose basically trying to create a self contained component which I can use again.

I don't know why I have been trying to do this more recently, I think it's because I want to be able to reuse more of the code I write and looking back at the code I have written before I can see that it's very difficult to reuse the code because it isn't really very modular and not very cohesive. The code I have written in the past seem to try and do to many things which ends up that lots of the code is too dependant on each other and means I can't take bits out and use them in other projects.

Anyway I found the article really useful as I do most of the articles involving Mr Bloch.

http://www.javaworld.com/javaworld/jw-01-2002/jw-0104-bloch_p.html

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home