Jump to a problem, path or page
Jump to a problem, path or page
01 · Develop the design
Use a ParkingService with replaceable allocation and pricing policies, a repository that atomically claims spots, and a ticket lifecycle that supports idempotent payment and exit.
Stage 1
Write the invariants first
One active ticket owns one compatible spot. A spot cannot belong to two active tickets. List ticket states before selecting design patterns.
Stage 2
Separate policy from orchestration
ParkingService coordinates work. AllocationStrategy ranks compatible spots; PricingStrategy computes a quote. The repository, not the strategy, enforces atomic claims.
Stage 3
Make exit a retryable workflow
An external payment cannot participate in a normal database transaction. Persist a stable payment identity, reconcile ambiguous responses, and release the spot once after confirmed payment.
02 · Work through the method
03 · Justify the choices
Where does spot selection belong?
In a replaceable AllocationStrategy contract
Separate selection policy from orchestration so nearest-spot and lowest-price strategies can change independently.
How do concurrent entries claim a spot?
Atomically claim an available spot in the repository
The repository must enforce an atomic transition from available to occupied; an in-memory precheck alone races.
How do repeated exit requests behave?
Use ticket/payment identity for an idempotent state transition
A ticket lifecycle and idempotency key prevent double charging and repeated release.
04 · Plan the evidence