bad smell (long method)

symptoms: a method contains too many lines of code.
treatment:
if you feel the need to comment on something inside a method, you should take this code and put it into a new method
1.extract method with a good name
(Extract Method refactoring has the following limitations:
Refactoring does not work with multiple output values in automatic mode. You have to change your code before applying the refactoring.
Refactoring does not work for a code fragment which conditionally returns from the containing method and is not placed at the end of it.即 function 裡面有提前return)

how to extract
find the local variables or parameters first
non modified variable in the segment pass as a parameter
modified variables in the segment initialized as local variables in the new method , in the end return the variables


2.replace temp with query (remove temp)

3.introduce parameter object (remove parameters)

4.preserve whole object

5.replace method with method object

6.decompose conditional