09 January 2007

Stop Being Clever

Many developers code with
reuse and flexibility in mind and
sometimes introduce additional
overhead into their programs.
At one time or another they’ve
written code similar to:
public void
doSomething(File file) {
FileInputStream fileIn = new FileInputStream(file);
// do something
}

It’s good to be flexible, but in this scenario they’ve created
more overhead. The idea behind doSomething is to manipulate
an InputStream, not a file, so it should be refactored as follows:

public void doSomething(InputStream inputStream){
// do something
}

reference:James McGovern

No comments: