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:
Put the following steps in order under this policy.
1.
Delete calc() once all teams have confirmed that no callers remain, then run the tests again.
2.
Publish documentation marking calc() as deprecated and naming its replacement, without adding runtime warnings.
3.
Add calculate_invoice_total() containing the original method body, and make calc() delegate to it without changing results, exceptions or side effects.
4.
Update every caller to use the new name, running the tests after each batch, and obtain migration confirmation from every consuming team.
5.
Run the existing tests and confirm that they all pass before changing anything.
Unlock full course notes by signing up
Complexity before and after Extract Method
A cinema prices tickets with the function below. Count each if and elif as one decision point; else counts as none.
A developer applies Extract Method to the age-based pricing:
Give the cyclomatic complexity MMM of the original ticket_price, of the new base_price and of the refactored ticket_price, each as a whole number. Then give the price in dollars, to two decimal places, that the refactored code returns for ticket_price(70, "Tue", True).
Moving the rounding boundary
A store applies a 10% discount to item prices recorded as nonnegative integer cents. A developer proposes the following Python change as a refactoring:
For these nonnegative values, // 10 divides by ten and discards any fractional part. Fill in both functions' returned totals for each basket. Enter exact integers in cents; do not apply any additional rounding.
An extraction that passed the tests
In Python, a developer refactors this checkout function:
into this version:
Every existing test calls checkout with coupon=False, and all of them pass. Consider a customer whose item prices sum to 40.00 dollars and who uses a coupon. Ignoring floating-point rounding, which statement is accurate?
Removing a temporary changes object sharing
A maintenance team proposes removing a temporary variable from a Python function that creates task queues. Task durations are stored as integer minutes. The proposed change is intended to preserve existing behavior.
The following client code runs once with each version, starting with fresh queues each time:
Calculate morning_total and backup_total for the original version, then calculate both totals for the proposed version. Enter all four results in minutes, to zero decimal places.