o Long method If you have a method with lots of parameters and temporary variables, these elements get in the way of extracting methods. You can often use Replace Temp with Query to eliminate the temps. Long lists of parameters can be slimmed down with Introduce Parameter Object and Preserve Whole Object. If you’ve tried that, and you still have too many temps and parameters, it’s time to get out the heavy artillery: Replace Method with Method Object. How do you identify the clumps of code to extract? To Look for COMMENTS. They often signal this kind of semantic distance. A block of code with a comment that tells you what it is DOING can be replaced by a method whose name is based on the comment. Even a single line is worth extracting if it needs explanation. Conditionals and loops also give signs for extractions. Use Decompose Conditional to deal with conditional expressions.
o Large Class When a class is trying to do too much, it often shows up as too many instance varaibles. When a class has too many instance variables , duplicated code cannot be far behind. Choose variables to go together in the component that makes sense for each. More generally, common prefixed or suffixes for some subset of the variables in a class suggest the opportunity for a component. if the component makes sense as a subclass , you’ll find Extract Subclass often is easier.
