Software
  • Introduction
  • Code craft
    • Clean code
    • Reusable code
    • Refactoring
    • Code smells
  • Service craft
  • Software Principles
  • Big Data
    • Introduction
    • Data modelling
  • Patterns
    • Enterprise patterns
    • Software patterns
  • Agile & proj management
    • Scrum vs Kanban
    • Kanban
    • Scrum
  • Conflict management
  • Reading
  • Software Architecture
    • Architecture components
Powered by GitBook
On this page
  • Before refactoring
  • Refactoring techniques
  • Abstract
  • Break-up code
  • Improve naming and location

Was this helpful?

  1. Code craft

Refactoring

PreviousReusable codeNextCode smells

Last updated 4 years ago

Was this helpful?

Before refactoring

  • Check the test coverage. If not sufficient, add more

  • Tests should pass before attempting to refactor

  • Ensure public access points/interfaces are well tested

  • Depending on the refactoring level, ensure some of the lower level aspects are tested as well

Refactoring techniques

Abstract

  • Encapsulate fields

  • Type checking/ cases => polymorphism

Break-up code

  • Large method => smaller multiple methods

  • Large class => smaller classes with limited responsibility

Improve naming and location

  • Hard constant value => variable with a constant value. Gives a better name and allows searchability

https://refactoring.guru/refactoring/techniques