23. Strategy
Choosing behaviour by handing an object in, rather than by branching at the call site
Checkout adds postage to an order, and the tests pass for both services.
It was handed a Postage and only uses it for the name — the rates are copied out into a private method with a branch per service.
Postage already declares cost(grams), and both services implement it. Rewrite Checkout to ask.
This overlaps Open/Closed, and it is worth being straight about how. Open/Closed is about not editing the thing that measures when a new kind of thing arrives. Strategy is about the caller picking behaviour by composition — the same shape, seen from the other end.
Run compiles every file and runs Tests.java — the tests you can read.
Submit runs those again, then applies 1 requirement you have not seen, one at a time.
Your code is never edited. Each requirement is added to the project as it stands. If the design is right, nothing you wrote has to change.
- Ctrl/⌘ + Enter runs the tests
Run the tests to see where you are.