The below will be my notes on each of the sections in Refactoring Improving the Design of Existing Code
- Composing Methods
- Moving Features Between Objects
- Organizing Data
- Self Encapsulate Field
- Replace Data Value with Object
- Change Value to Reference
- Change Reference to Value
- Replace Array with Object
- Duplicate Observed Data
- Change Unidirectional Association to Bidirectional
- Change Bidirectional Association to Unidirectional
- Replace Magic Number with Symbolic Constant
- Encapsulate Field
- Encapsulate Collection
- Replace Record with Data Class
- Replace Type Code with Class
- Replace Type Code with Subclasses
- Replace Type Code with State/Strategy
- Replace Subclass with Fields
- Simplifying Conditional Expressions
- Making Method Calls Simpler
- Rename Method
- Add Parameter
- Remove Parameter
- Separate Query from Modifier
- Parameterize Method
- Replace Parameter with Explicit Methods
- Preserve Whole Object
- Replace Parameter with Method
- Introduce Parameter Object
- Remove Setting Method
- Hide Method
- Replace Constructor with Factory Method
- Encapsulate Downcast
- Replace Error Code with Exception
- Replace Exception with Test
- Dealing with Generalization
- Big Refactorings
https://refactoring.com/catalog/extractMethod.html
- Helps provide clarity of purpose for the enclosed statements
- Removes the need for comments when using expressive method names
- Consider using even over short pieces of code that are semantically dense
- Consider using if inside the method the statements deal with different layers of abstraction
- Don't use if the extracted piece of code cannot be given a better name than the current method's
https://refactoring.com/catalog/inlineMethod.html
- Helps with needless indirection
- Consider using as an intermediate step to cleaning up badly factored, smaller methods
- Don't use if a subclass overrides the method
https://refactoring.com/catalog/inlineTemp.html
- Only use when assigning the value of a method call
- Consider using as an intermediate step when refactoring to a Replace Temp with Query
https://refactoring.com/catalog/replaceTempWithQuery.html
- Helps reduce method size by extracting a commonly used query
- Consider using if a given expression is used only once within the method
- Consider using if the temp variable is only assigned to once within the method
https://refactoring.com/catalog/extractVariable.html
- Helps with expressiveness of conditional statements
- Consider using if many conditionals are being considered
- Consider using Extract Method for the conditional statement if it is a recurring check instead
- Often leads to Replace Temp With Query
https://refactoring.com/catalog/splitTemporaryVariable.html
- Consider using if you are re-using a temp variable
- Helps refactor code to follow Single Responsibility Principle
- Can likely be identified if the name of the variable does not express what it's used for in a meaningful way (temp, foo, etc.)
https://refactoring.com/catalog/removeAssignmentsToParameters.html
- Avoid assigning value to parameters, instead use a temp variable
- Helps avoid clarity issues between pass by reference and pass by value
- Output parameters are an exception but should be used in very limited circumstances
https://refactoring.com/catalog/replaceMethodWithMethodObject.html
- Introduces the Command Pattern
- Reduces duplication in common work by encapsulating that functionality in an object
https://refactoring.com/catalog/substituteAlgorithm.html
- Given two algorithms, select the one that is either
- More performant
- More succinct
- More expressive
- Have tests that assert the result of the original algorithm and run them after replacing to insure the new algorithm is a proper substitute