Extending BigDecimal?

Viewed 4650

I've a fair bit of code using BigDecimal Class and I hate the clumsiness of the interface.

I've alleviated the pain of using BigDecimals with integers by creating a helper class with static methods with the following methods:

compare(BigDecimal first, int second)
divide(BigDecimal dividend, BigDecimal divisor, int scale)
divide(BigDecimal dividend, int divisor, int scale)
divide(int divident, int divisor, int scale)
multiply(BigDecimal first, BigDecimal second, int scale)
multiply(BigDecimal first, int second, int scale)
multiply(int first, int second, int scale)
zeroPad(BigDecimal value, int totalLength, int scale)

That's all I need for now and the code is a little more readable than before. However, I read that static methods are a "bad" thing and that they don't follow OO-principles.

If I extend BigDecimal however, I'd define a new type and thus I'd have to re-define all methods to wrap them with my object or I won't be able to use the results with the augmented methods. It doesn't seem a smart thing to do.

How would you approach this problem?

5 Answers
Related