Saturday, January 8, 2011

is this code Clean ? or is it my mind .....

I just completed reading chapter 15 of the famous CleanCode book by @unclebobmartin but  there is something that makes me feel uneasy.

    The chapter was illustrating the process of refactoring an existing class from the junit framework , the final draft was really inspiring and beautiful. But my problem is the way that class is designed on a whole , to draw a simple comparison , consider a class for adding 2 numbers , let us call Adder such that 1> Adder myAdder = new Adder(3,2); 2> int sum = myAdder.add();  
    Please excuse me if the above example looks too naive but the point i am trying to make here is why should i write a stateful class which is immutable anyways and utility is to expose behaviour for which it acts only on its initialized state .  
    The only justification for such construction are the standard type wrappers e.g String, Integer al. But to write a such a class with the intention of using it as a general utility doesn't make sense to me or am i missing something here, please share ur thhoughts on this.  
    This particular construct is very recurrent in the examples of that book and makes me curious at its apparent incongruence with everything that book stands for and hence i think  should discover the logic