Lean on the good tests. Improve the code in ShoppingCart.
What are you hoping to achieve, when you sit down to refactor some code? What is your motivation?
Examples of behaviour-preserving transformations for conditionals. I started a repo for some of these.
Working on SupermarketReceipt. You have several if statements that assign a value to ‘x’ and several that assign a value to ‘discount’. One assigns both. You’d like to do ‘split loop’ on that if statement. Then you can use ‘slide statement’ and ‘extract method’ so you have one method to calculate ‘x’ and one to calculate the discount.
Explain this plan and note it on the whiteboard.
Set the group loose on the refactoring. Remind them of the plan, and remind them to use their tools.
How would you spot other situations where you can use ‘split loop’, ‘slide statement’ and ‘extract method’?