Skip to main content
REFACTORING-BASICS5 MIN READ

Extract a Pricing Rule Without Moving the Bug

Execute Extract Function as a sequence of behavior-preserving steps.

Fix the premium-plan discount rule hidden inside a long invoice builder without making the bug fix harder to review. Extract Function: name the policy, preserve behavior, then change the policy. Changing the discount conditional in place mixes policy change with navigation through logging, formatting, and subtotal code. If the test fails, nobody knows whether the extraction or the rule caused it. Find the coherent idea Select only the lines that decide the premium discount rate. The slice has one job and a name the caller can read. Extract without editing logic Move those lines to premiumDiscountRate(customer, invoice) and pass the…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us