To express in very simple way, Refactoring is rewriting the existing code. But why should you? Hmm. we need to go for something better. Lets try again. Refactoring is changing the existing code to restructure the design which will be easier to understand or decrease total amount of code or maximize the use of same piece of code or cutting of deprecated methods by using new but do not change the observable behavior of the code.
Most of the time, its not like you start refactoring as a task. There are very few scenario that leads refactoring as independent task. Most of the time people do it while developing a feature. Better to say Feature Mode and Factoring Mode at the same time. Think of a scenario. Suppose You have a method that takes no of seconds as input and print number of minits and hours by that amount of seconds by simply divide by 60 and again by 60.
void printHourMin(long seconds) {
long min = seconds/60;
long hour = min/60;
System.out.println(min);
System.out.println(hour);
}
Now you need to print no of Hours only in another feature. What you would do? write a new method to do that feature? I do believe no. You may like to Re-factor the existing code.
void printHourMin(long seconds) {
long min = seconds/60;
System.out.println(min);
printHour(min)
}
void printHour(long min) {
long hour = min/60;
System.out.println(hour);
}
This two method can serve the perpose of two different requirement but minimize the number of code as well as readability. Well this could be example of very simple refactoring. But the field is too massive, it is consists of too many techniques and ideas.
By: Md. Shahjalal
Posted by Md. Shahjalal 
