Every Carrier Does It Differently
Three carriers price, label and schedule pickups their own way, and the tracker shouldn't care which one it's talking to.
Updated
Rates That Need More Than a Function
- Strategy: When the Rule Needs a Class of Its Own (Journeyman): Pass 1 handed the weekly deal in as one function; a carrier's rate needs its own numbers and answers more than one question, so the function grows into a class per carrier, each holding its numbers and keeping one promise, and the quote screen asks whichever carrier it's handed: the Strategy pattern in its classic form.
Same Steps, One Step Different
- Template Method: Same Routine, Your Own Step (Journeyman): When three label classes copy the same four steps and differ only in the barcode, a fix to the shared steps has to be made three times, and one copy is always missed; writing the routine once in a base class and letting each carrier's subclass fill in its own barcode is the Template Method pattern.
- Strategy or Template Method? (Journeyman): Strategy and Template Method both let one step of a routine vary: Strategy hands the step in as an object or function (has-a), Template Method leaves it for a subclass to fill in (is-a); a look-alike table, a run-time change and a second varying step show what each costs, and why most teams reach for Strategy first.
Let Each Carrier Decide
- Factory Method: Let Each Carrier Decide (Journeyman): Pass 1's simple factory picked a class from a name; when shipping runs the same steps for every carrier and needs both a label and a pickup that must match, two simple factories with the same if chain drift apart, so each carrier's subclass decides what to create, with methods the shared steps call: the Factory Method pattern.
Exercise: The Shipping Rate Calculator
- Exercise: The Shipping Rate Calculator (Journeyman): Take the operations manager's ticket: a fourth carrier, NightOwl, has written its own rules against the tracker's carrier promise. Change a working rate desk, whose carriers are tangled into one switch, so any carrier it's handed can be quoted, with the tests green throughout.