Renaming a public method safely

A shared library exposes a public method calc() that several other teams' services call. You want to rename it to calculate_invoice_total() while preserving callers' return values, exceptions and side effects. All callers are known, and delegation is assumed to preserve this behaviour.


Follow the library's required rollout policy:

  • Confirm that the existing tests pass before editing code.
  • Make both method names available before publishing a documentation-only deprecation notice.
  • Publish that notice before beginning caller migration; introduce no runtime warnings.
  • Remove the old name only after every consuming team confirms that all its callers have migrated.

Put the following steps in order under this policy.

  1. 1.

    Delete calc() once all teams have confirmed that no callers remain, then run the tests again.

  2. 2.

    Publish documentation marking calc() as deprecated and naming its replacement, without adding runtime warnings.

  3. 3.

    Add calculate_invoice_total() containing the original method body, and make calc() delegate to it without changing results, exceptions or side effects.

  4. 4.

    Update every caller to use the new name, running the tests after each batch, and obtain migration confirmation from every consuming team.

  5. 5.

    Run the existing tests and confirm that they all pass before changing anything.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Refactoring Questions: