└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # Refactorings List 2 | The below will be my notes on each of the sections in Refactoring Improving the Design of Existing Code 3 | 4 | - **Composing Methods** 5 | - [Extract Method](#extract-method) 6 | - [Inline Method](#inline-method) 7 | - [Inline Temp](#inline-temp) 8 | - [Replace Temp with Query](#replace-temp-with-query) 9 | - [Introduce Explaining Variable](#introduce-explaining-variable) 10 | - [Split Temporary Variable](#split-temporary-variable) 11 | - [Remove Assignments to Parameters](#remove-assignments-to-parameters) 12 | - [Replace Method with Method Object](#replace-method-with-method-object) 13 | - [Substitute Algorithm](#substitute-algorithm) 14 | - **Moving Features Between Objects** 15 | - [Move Method](#move-method) 16 | - [Move Field](#move-field) 17 | - [Extract Class](#extract-class) 18 | - [Inline Class](#inline-class) 19 | - [Hide Delegate](#hide-delegate) 20 | - [Remove Middle Man](#remove-middle-man) 21 | - [Introduce Foreign Method](#introduce-foreign-method) 22 | - [Introduce Local Extension](#introduce-local-extension) 23 | - **Organizing Data** 24 | - [Self Encapsulate Field](#self-encapsulate-field) 25 | - [Replace Data Value with Object](#replace-data-value-with-object) 26 | - [Change Value to Reference](#change-value-to-reference) 27 | - [Change Reference to Value](#change-reference-to-value) 28 | - [Replace Array with Object](#replace-array-with-object) 29 | - [Duplicate Observed Data](#duplicate-observed-data) 30 | - [Change Unidirectional Association to Bidirectional](#change-unidirectional-association-to-bidirectional) 31 | - [Change Bidirectional Association to Unidirectional](#change-bidirectional-association-to-unidirectional) 32 | - [Replace Magic Number with Symbolic Constant](#replace-magic-number-with-symbolic-constant) 33 | - [Encapsulate Field](#encapsulate-field) 34 | - [Encapsulate Collection](#encapsulate-collection) 35 | - [Replace Record with Data Class](#replace-record-with-data-class) 36 | - [Replace Type Code with Class](#replace-type-code-with-class) 37 | - [Replace Type Code with Subclasses](#replace-type-code-with-subclasses) 38 | - [Replace Type Code with State/Strategy](#replace-type-code-with-state/strategy) 39 | - [Replace Subclass with Fields](#replace-subclass-with-fields) 40 | - **Simplifying Conditional Expressions** 41 | - [Decompose Conditional](#decompose-conditional) 42 | - [Consolidate Conditional Expression](#consolidate-conditional-expression) 43 | - [Consolidate Duplicate Conditional Fragments](#consolidate-duplicate-conditional-fragments) 44 | - [Remove Control Flag](#remove-control-flag) 45 | - [Replace Nested Conditional with Guard Clauses](#replace-nested-conditional-with-guard-clauses) 46 | - [Replace Conditional with Polymorphism](#replace-conditional-with-polymorphism) 47 | - [Introduce Null Object](#introduce-null-object) 48 | - [Introduce Assertion](#introduce-assertion) 49 | - **Making Method Calls Simpler** 50 | - [Rename Method](#rename-method) 51 | - [Add Parameter](#add-parameter) 52 | - [Remove Parameter](#remove-parameter) 53 | - [Separate Query from Modifier](#separate-query-from-modifier) 54 | - [Parameterize Method](#parameterize-method) 55 | - [Replace Parameter with Explicit Methods](#replace-parameter-with-explicit-methods) 56 | - [Preserve Whole Object](#preserve-whole-object) 57 | - [Replace Parameter with Method](#replace-parameter-with-method) 58 | - [Introduce Parameter Object](#introduce-parameter-object) 59 | - [Remove Setting Method](#remove-setting-method) 60 | - [Hide Method](#hide-method) 61 | - [Replace Constructor with Factory Method](#replace-constructor-with-factory-method) 62 | - [Encapsulate Downcast](#encapsulate-downcast) 63 | - [Replace Error Code with Exception](#replace-error-code-with-exception) 64 | - [Replace Exception with Test](#replace-exception-with-test) 65 | - **Dealing with Generalization** 66 | - [Pull Up Field](#pull-up-field) 67 | - [Pull Up Method](#pull-up-method) 68 | - [Pull Up Constructor Body](#pull-up-constructor-body) 69 | - [Push Down Method](#push-down-method) 70 | - [Push Down Field](#push-down-field) 71 | - [Extract Subclass](#extract-subclass) 72 | - [Extract Superclass](#extract-superclass) 73 | - [Extract Interface](#extract-interface) 74 | - [Collapse Hierarchy](#collapse-hierarchy) 75 | - [Form Template Method](#form-template-method) 76 | - [Replace Inheritance with Delegation](#replace-inheritance-with-delegation) 77 | - [Replace Delegation with Inheritance](#replace-delegation-with-inheritance) 78 | - **Big Refactorings** 79 | - [Tease Apart Inheritance](#tease-apart-inheritance) 80 | - [Convert Procedural Design to Objects](#conver-procedural-design-to-objects) 81 | - [Separate Domain from Presentation](#separate-domain-from-presentation) 82 | - [Extract Hierarchy](#extract-hierarchy) 83 | 84 | --- 85 | # Composing Methods 86 | ## Extract Method 87 | https://refactoring.com/catalog/extractMethod.html 88 | 89 | - Helps provide clarity of purpose for the enclosed statements 90 | - Removes the need for comments when using expressive method names 91 | - Consider using even over short pieces of code that are semantically dense 92 | - Consider using if inside the method the statements deal with different [layers of abstraction](http://principles-wiki.net/principles:single_level_of_abstraction) 93 | - Don't use if the extracted piece of code cannot be given a better name than the current method's 94 | 95 | ## Inline Method 96 | https://refactoring.com/catalog/inlineMethod.html 97 | 98 | - Helps with needless indirection 99 | - Consider using as an intermediate step to cleaning up badly factored, smaller methods 100 | - Don't use if a subclass overrides the method 101 | 102 | ## Inline Temp 103 | https://refactoring.com/catalog/inlineTemp.html 104 | 105 | - Only use when assigning the value of a method call 106 | - Consider using as an intermediate step when refactoring to a [Replace Temp with Query](##replace-temp-with-query) 107 | 108 | ## Replace Temp with Query 109 | https://refactoring.com/catalog/replaceTempWithQuery.html 110 | 111 | - Helps reduce method size by extracting a commonly used query 112 | - Consider using if a given expression is used only once within the method 113 | - Consider using if the temp variable is only assigned to once within the method 114 | 115 | ## Introduce Explaining Variable 116 | https://refactoring.com/catalog/extractVariable.html 117 | 118 | - Helps with expressiveness of conditional statements 119 | - Consider using if many conditionals are being considered 120 | - Consider using [Extract Method](##extract-method) for the conditional statement if it is a recurring check instead 121 | - Often leads to [Replace Temp With Query](##replace-temp-with-query) 122 | 123 | 124 | ## Split Temporary Variable 125 | https://refactoring.com/catalog/splitTemporaryVariable.html 126 | 127 | - Consider using if you are re-using a temp variable 128 | - Helps refactor code to follow [Single Responsibility Principle](http://principles-wiki.net/principles:single_responsibility_principle) 129 | - 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.) 130 | 131 | ## Remove Assignments to Parameters 132 | https://refactoring.com/catalog/removeAssignmentsToParameters.html 133 | 134 | - Avoid assigning value to parameters, instead use a temp variable 135 | - Helps avoid clarity issues between pass by reference and pass by value 136 | - Output parameters are an exception but should be used in very limited circumstances 137 | 138 | ## Replace Method with Method Object 139 | https://refactoring.com/catalog/replaceMethodWithMethodObject.html 140 | 141 | - Introduces the [Command Pattern](https://sourcemaking.com/design_patterns/command/java/2) 142 | - Reduces duplication in common work by encapsulating that functionality in an object 143 | 144 | ## Substitute Algorithm 145 | https://refactoring.com/catalog/substituteAlgorithm.html 146 | 147 | - Given two algorithms, select the one that is either 148 | - More performant 149 | - More succinct 150 | - More expressive 151 | - Have tests that assert the result of the original algorithm and run them after replacing to insure the new algorithm is a proper substitute 152 | 153 | # Moving Features Between Objects 154 | ## Move Method 155 | https://refactoring.com/catalog/moveMethod.html 156 | --------------------------------------------------------------------------------