I am reading Martin Fowlers Refactoring book. On page 110 he talks about 'Replace Method with Method Object' where he turns a method with local variables into a class with instance variables.
The outcome is a class called: PriceCalculator with three instance variables i.e. primaryBasePrice, secondaryBasePrice and teritary base price.
I recently asked a question about local variables and instance variables: When should local variables be used over instance variables?. I agree with Samuels answer and Timothy Truckles' answer - I have always used the principle of least visibility in my work.
However, Fowlers refactoring seems to contradict this and is confusing me. Also all the class diagrams in my UML book seem to contradict the principle of least visibility i.e. they use a class with instance variables regardless of the scenario like this one: http://www.newthinktank.com/wp-content/uploads/2012/12/Object-Oriented-Design.png. I understand that you have to compromise in this game when considering performance etc. Is it "better" design to have instance variables rather than local variables?