Tuesday, December 06, 2005

HumaneInterface, Ruby and TDD

Ijust read the new entry By Martin Fowler about HumaneInteraces. Its pointing out that the Ruby language developers paid attention to end user need and came up with convienience methods even though it did cause bit of a method explosion. He used Array class and contrasted withjava.util.List interface. I agree with his post.
I would like to add to that test driven development tends to lead towards humane interfaces (The part about being having convinience methods be part of the object signature). I think that is because developers will end up thinking of a method to implement as part of the functionality and that is usually based on the input we usually consider for that method.

For example, lets say that you need to implement a method that would retrieve some information about an employee. We start off with a test with a method on the class, say, findEmployee(String name). Because, as humans, we tend to write code starting with the input and it usually is from a name.. Then we find out that the underlying collaborator (say EmployeeDAL) accepts only IDs. Now you endup with another method, say findEmployee(int id).. At this point, you endup with another method findIdForEmployee(String name). We can potentially remove the findEmployee(String name) since it can be achieved through a combination of findIdForEmployee + findEmployee(id). I contend that we should leave the earlier method as is since it provides a convenient interface to the caller.

My 2c..


0 Comments:

Post a Comment

<< Home