Refactoring

Refactoring is the systematic modification of a software system's internal structure without changing its external behaviour, aimed at improving nonfunctional attributes of the software.

Goal

To enhance the maintainability, readability, and performance of the codebase, facilitating easier updates, faster bug fixes, and more efficient feature development.

Context

Code tends towards complexity. As we layer on new features, fix bugs, and make changes, the codebase can become harder to understand and maintain. Refactoring is a critical practice to streamline the design of the codebase and keep the codebase clean, organised, and efficient over time.

Techniques

TechniqueDescriptionMethods
Composing MethodsTechniques for simplifying methods, making them smaller, and more focused.Extract Method, Inline Method, Inline Temp, Replace Temp with Query, Introduce Explaining Variable
Moving Features between ObjectsApproaches for reassigning responsibilities between classes to improve coherence or reduce dependencies.Move Method, Move Field, Extract Class, Inline Class, Hide Delegate
organising DataRefactoring that improves how data is managed and accessed within an application.Encapsulate Field, Encapsulate Collection, Replace Data Value with Object, Change Value to Reference
Simplifying Conditional ExpressionsTechniques to make conditional logic clearer and easier to manage.Decompose Conditional, Consolidate Conditional Expression, Replace Nested Conditional with Guard Clauses
Making Method Calls SimplerMethods aimed at simplifying how methods and functions are called and used.Rename Method, Add Parameter, Remove Parameter, Separate Query from Modifier
Dealing with GeneralisationTechniques for refining class hierarchies and object inheritance to make them more logical and easier to understand.Pull Up Method, Push Down Method, Extract Subclass, Extract Superclass, Replace Inheritance with Delegation

Inputs

ArtifactDescription
CodebaseThe existing source code that is subject to refactoring.

Outputs

ArtifactDescriptionBenefits
Refactored CodeThe updated codebase after refactoring has been applied.Improves code quality and reduces the risk of bugs or errors.

Anti-patterns

  • Random Refactoring: Refactoring without clear goals or understanding of the existing codebase, leading to unnecessary changes.
  • Perfectionism: Excessive refactoring that focuses on perfectionism rather than delivering value.
  • Lack of Testing: Neglecting to test refactored code thoroughly, risking the introduction of new bugs.

Was this page helpful?

Previous
Code Ownership
© ZeroBlockers, 2024. All rights reserved.