Design a locker service. A courier drops a package into a free locker that fits, the customer gets a one-time code, and opens the locker with it. Uncollected packages are returned after a few days.
Model what physically exists.
We have a list of requirements but no model of lockers or codes. `LockerSize` enum, `Package` with a size, `Locker` with a size and an occupied flag, and a `PickupCode` that expires and can be used once. A package fits a locker when its size is not larger, so the size is a number-like enum, not text. A code is its own object, not a field on `Package`, because it has its own life: it expires and is used once.
Give the deposit and pickup flow an owner.
Who finds a free locker, issues a code and checks it on pickup? `Location` knows its lockers and can find a free one that fits. `LockerService.deposit` finds a locker, stores the package and issues a code; `pickup` checks the code and opens the door. The service is the only entry point, so the rules (one use, not expired) are enforced in one place. `findFree` scans all lockers. Fine for a location of 60, and an index by size if it grows.
Make allocation swappable.
Should a small package use a large locker when small ones are full? The answer is a policy. A `LockerAllocation` interface; `SmallestFit` implements it. The service asks the strategy instead of scanning itself. Changing the policy (closest to the door, balance wear) is a new class (**Strategy**). To make the choice **safe** under two couriers, the chosen locker must be marked occupied in the same locked step.
A locker behaves by its state; stale packages expire.
An occupied locker must refuse a deposit and a free one must refuse a pickup, and a 3-day timer must free stale lockers. `LockerState` with `FreeState` and `OccupiedState` so each decides what is allowed. `ExpirySweeper` periodically asks the service to expire old codes. The if-chains on `occupied` disappear (**State**). Expiry is a separate small job, not a check scattered through the flow. A sweep runs on a timer, so a package may sit a few minutes past 3 days. Check expiry on pickup as well.