Defactoring
Reducing Cognitive Load by Removing Unnecessary Abstraction
refactoring
Defactoring
Defactoring is Reducing Cognitive Load by Removing Unnecessary Abstraction. Good Abstractions are a matter of balance. Defactoring technically is still refactoring, but it involves reversing a refactoring.
Reversals of our previous refactorings:
- Extract Method -> Inline Method
- Extract Variable -> Inline Variable
- Extract Class -> Inline Class
- Introduce Field -> Inline Field
- Introduce Parameter -> Inline Parameter
Defactoring by Inlineing:
// AS-IS
fun addParens(value: String): String {
val str = "($value)"
return str
}
// TO-BE
fun addParens(value: String) = "($value)"
Refactoring is a controlled technique for improving the design of an existing code base. Its essence is applying a series of small behavior-preserving transformations, each of which "too small to be worth doing".
Factoring is “God Object,” and breaking it out into various entities with individual responsibilities.