recall

← recall

sprout method pattern

When adding a feature to legacy code, resist editing the gnarly bits. Write a new method (or class) that contains the new behavior; call it from the smallest possible point in the legacy. Keeps the new code testable and reviewable; leaves the legacy untouched.

When adding a feature to legacy code, resist editing the gnarly bits. Write a new method (or class) that contains the new behavior; call it from the smallest possible point in the legacy. Keeps the new code testable and reviewable; leaves the legacy untouched.

symptoms

  • need a new feature in untested legacy
  • editing the old method risks breaking things

causes

  • legacy without seams or coverage

fixes

  • new method with the new behavior
  • minimal call site in the legacy
  • new method is testable + reviewable

you might say

  • sprout method
  • sprout class
  • new code in a new place

related

topics: legacy-code, refactoring

references: