Thursday, March 09, 2006

Overcoming the problem with static methods in Java

There's a number of possible solutions that I've recently had the opportunity to see other people try in test driving static methods. Generally, when I've come across it it's been a refactoring job.

The general process is: create interface and change the statics to be just normal member variables on the class.

The problem is when it's something you can't change, for whatever reason.

If you've been left the chance to extend it you can simple add methods that wrap the statics and base these new methods on an interface.

If you're unable to extend it then you create a wrapper (or boundary) class and a matching interface.
Post a Comment