Skip to content
UoL CS Notes

Refactoring

COMP285 Lectures

Refactoring is where we improve our code quality while maintaining the same functionality. This yields better:

  • Readability
  • Testing
  • OO Structure
  • Re-usability
  • Efficiency
  • Extend-ability

Code Smell

These are issues with the code that aren’t bugs. They are bad coding practices:

  • Duplicated Code
    • We should use generalised classes that we can extend if we need similar, but different, functionality.
  • Long Methods
    • We should split long methods into functions to aid code reuse.
  • Long Argument Lists
    • Collections of data should be wrapped in a type.
    • Data that required validation should have it’s own type so that invalid data can never be passed to a function.
  • Large Classes
    • Make sure we are using super-classes properly.
    • Generalise functions (pull-up), or specialise (push-down).
      • When generalising methods see if making an interface would be appropriate.
  • Excessively Long Identifiers
  • Excessively Short Identifiers
  • Inappropriate Intimacy
    • Where one class writes data directly into another classes attribute.
    • We should avoid having any public attributes.