Essence and Refactorings

The following table relates refactorings to relative essence. It lists all the refactorings from Fowler's "Refactoring" book, and it also includes the refactorings from Fowler's online refactoring catalog (except for the J2EE-specific refactorings). Column 'Fowler' refers to the page in Fowler's book describing this refactoring. It displays "web" if the refactoring appears in the online catalog only. Column 'Kind' characterizes the type of refactoring (according to Fowler). Column 'Essence' describes the correlation of the refactoring with relative essence: "+" (refactoring increases relative essence), "0" (no direct relationship between relative essence and refactoring), and "-" (refactoring decreases relative essence).

Fowler Kind Refactoring Essence Comment
page 275 Making Method Calls Simpler Add Parameter 0
page 200 Organizing Data Change Bidirectional Association to Unidirectional 0 + may be able to remove accessors, target object will have to access source object via loop
page 183 Organizing Data Change Reference to Value (-) (+) often requires adding equals and hashcode methods but also may eliminate factory method
page 197 Organizing Data Change Unidirectional Association to Bidirectional - 0 may have to introduce accessors, no more need for extra loops to find source object from target object
page 179 Organizing Data Change Value to Reference (-) (+) introduces factory method, but may allow removing equals and hashcode methods
page 344 Dealing with Generalization Collapse Hierarchy + class gets removed, also constructor + overridden methods if they exist
page 240 Simplify Conditional Expressions Consolidate Conditional Expressions - includes 'Extract Method'
page 243 Simplify Conditional Expressions Consolidate Duplicate Conditional Fragments 0
web Convert Dynamic to Static Construction 0 but may trigger other refactorings that increase relative essence
web Convert Static to Dynamic Construction 0 but may trigger other refactorings that decrease relative essence
page 238 Simplify Conditional Expressions Decompose Conditional - includes 'Extract Method'
page 189 Organizing Data Duplicate Observed Data - adds 'Observer'
page 208 Organizing Data Encapsulate Collection -
page 308 Making Method Calls Simpler Encapsulate Downcast -
page 206 Organizing Data Encapsulate Field -
page 149 Moving Features Between Objects Extract Class - 0 decrease if we need to introduce wrapper methods, delegation, accessors
page 341 Dealing with Generalization Extract Interface 0
page 110 Composing Methods Extract Method -
web Extract Package 0
page 330 Dealing with Generalization Extract Subclass (-) 0 may decrease due to subclass constructor, and if subclass overrides methods of superclass
page 336 Dealing with Generalization Extract Superclass (-) 0 may decrease due to new superclass constructor; maybe some effect if original methods in subclasses can be removed
page 345 Dealing with Generalization Form Template Method -
page 157 Moving Features Between Objects Hide Delegate - introduces methods that are just delegating
page 303 Making Method Calls Simpler Hide Method 0
page 154 Moving Features Between Objects Inline Class 0 + increase if there originally was a wrapper method we can remove
page 117 Composing Methods Inline Method +
page 119 Composing Methods Inline Temp 0
page 267 Simplify Conditional Expressions Introduce Assertion 0
page 124 Composing Methods Introduce Explaining Variable 0
page 162 Moving Features Between Objects Introduce Foreign Method -
page 164 Moving Features Between Objects Introduce Local Extension - because we create a new method (like in 'Extract Method')
page 260 Simplify Conditional Expressions Introduce Null Object - because we create new methods in Null Object, and those contain no loops
page 295 Making Method Calls Simpler Introduce Parameter Object (-) may need new class with at least a constructor and probably no loops
web Move Class 0
page 146 Moving Features Between Objects Move Field 0 (+) may increase if now unnecessary accessors can be removed
page 142 Moving Features Between Objects Move Method - 0 decrease, if original method is turned into a delegating wrapper
page 283 Making Method Calls Simpler Parameterize Method - + decrease if methods were essential, increase if methods were inessential
page 288 Making Method Calls Simpler Preserve Whole Object 0 (+) may increase if now unnecessary accessors can be removed
page 325 Dealing with Generalization Pull Up Constructor Body - 0 may replace automatically generated constructor of super class or may introduce a new constructor
page 320 Dealing with Generalization Pull Up Field 0 + may be able to remove some accessors
page 322 Dealing with Generalization Pull Up Method - 0 + if loopy method is pulled up then decrease and if non-essential then increase
page 329 Dealing with Generalization Push Down Field 0
page 328 Dealing with Generalization Push Down Method 0
web Reduce Scope of Variable 0
page 131 Composing Methods Remove Assignments to Parameters 0
page 245 Simplify Conditional Expressions Remove Control Flag - 0 if flag was used for an inner loop, may decrease the number of loops
web Remove Double Negative - 0 decreases if you don't replace method but create extra indirection
page 160 Moving Features Between Objects Remove Middle Man + removes methods that were just delegating
page 277 Making Method Calls Simpler Remove Parameter 0
page 300 Making Method Calls Simpler Remove Setting Method -
page 273 Making Method Calls Simpler Rename Method 0
page 186 Organizing Data Replace Array with Object - 0 may decrease due to introduction of accessor methods
web Replace Assignment with Initialization 0
page 255 Simplify Conditional Expressions Replace Conditional with Polymorphism - 0 distributes same computation over potentially more methods
web Replace Conditional with Visitor - introduces new methods (at least visit+accept instead of previously zero or one methods)
page 204 Making Method Calls Simpler Replace Constructor with Factory Method - introduces new factory method
page 175 Organizing Data Replace Data Value with Object - new class requires constructor and probably accessors
page 355 Dealing with Generalization Replace Delegation with Inheritance + no delegating methods needed
page 310 Making Method Calls Simpler Replace Error Code with Exception - 0 may decrease if new exception class has to be created
page 315 Making Method Calls Simpler Replace Exception with Test 0 + may increase if previously used exception class can be removed
page 352 Dealing with Generalization Replace Inheritance with Delegation - may need to introduce delegating methods
web Replace Iteration with Recursion 0 essential node (loop) replaced with essential node (recursion header method)
page 204 Organizing Data Replace Magic Number with Symbolic Constant 0
page 135 Composing Methods Replace Method with Method Object - introduces constructor plus accessors or delegation methods
page 250 Simplify Conditional Expressions Replace Nested Conditional with Guard Clauses 0
page 285 Making Method Calls Simpler Replace Parameter with Explicit Methods -
page 292 Making Method Calls Simpler Replace Parameter with Method 0
page 217 Organizing Data Replace Record with Data Class - introduces constructor
web Replace Recursion with Iteration 0 essential node (recursion header method) replaced with essential node (loop method)
web Replace Static Variable with Parameter 0
page 232 Organizing Data Replace Subclass with Fields +
page 120 Composing Methods Replace Temp with Query -
page 218 Organizing Data Replace Type Code with Class - introduces class with at least a constructor
page 227 Organizing Data Replace Type Code with State/Strategy -
page 223 Organizing Data Replace Type Code with Subclasses -
web Reverse Conditional 0
page 171 Organizing Data Self Encapsulate Field -
page 279 Making Method Calls Simpler Separate Query from Modifier -
web Split Loop + turns one loop into two
page 128 Composing Methods Split Temporary Variable 0
page 139 Composing Methods Substitute Algorithm - 0 + depends on algorithm
page 362 Big Refactorings Tease Apart Inheritance - 0 maybe new accessors
page 368 Big Refactorings Convert Procedural Design to Objects - introduces at least constructors
page 370 Big Refactorings Separate Domain from Presentation - 0 might introduce new methods
page 375 Big Refactorings Extract Hierarchy - 0 + may lead to more constructors but fewer accessors

Analysis

Of the 85 refactorings, only 18 may increase relative essence (14 strongly, 4 of those to a lower degree). A much larger fraction, 47 refactorings, may decrease relative essence (42 strongly, 5 to a lower degree). Three pairs of refactorings most directly relate to relative essence: 'inline method' and 'extract method', 'remove middle man' and 'hide delegate', and 'replace delegation with inheritance' and 'replace inheritance with delegation'. For each of these pairs, the first refactoring increases relative essence and the second refactoring (representing the inverse transformation) decreases relative essence. The first two pairs directly introduce or remove delegation. The last pair is a bit more subtle. It transforms between delegation and inheritance. Inheritance could be seen as an implicit form of delegation (dynamic method lookup instead of asking the application code for finding the delegate).