Wednesday, February 27, 2008

Canonical Implementations

A few days ago, a colleague made a tongue-in-cheek remark about the fact that I am directly using some Spring Framework helper classes (in this case: FileCopyUtils). First, I started to wonder if this was really bad: after all, are we not we supposed to avoid direct dependency to any framework?

Then it struck me as an evidence: the Spring Framework provides canonical implementations for almost anything.

Sure, it is all bound together thanks to the dependency injection kernel. But, whether it is via direct access to helper classes or via configuration, Spring implements state of the art and rock solid implementations of most of the tricky things you want to do.

Like copying streams while handling all the checked exceptions correctly. Or reading from a JMS destination with a configurable pool of consumers. Or creating and applying aspects. Or registering MBeans. Or... whatnot...

So why writing code when you can re-use one that has been so many times read, executed and improved over the past few years?

Why not tapping this huge source of canonical implementations?