Design the software for a multi-level parking lot. Drivers arrive in a motorcycle, car or truck, get a ticket at the gate, park in a free spot that fits, and pay when they leave.
Turn the nouns in the requirements into classes.
A list of requirements is not a design yet. We need the objects those sentences talk about. Every noun that matters becomes a class: `Vehicle`, `ParkingSpot`, `Ticket`. A `VehicleType` enum names the three sizes, so a spot can say which vehicles fit it. An enum fixes a small set of values, so 'truck' can never be mistyped. `Ticket` links a vehicle to a spot, so we always know who is parked where. Separate `Car`, `Motorcycle` and `Truck` classes would add code for no extra behaviour. One `Vehicle` with a type is enough until vehicles really behave differently.
Give the building a structure and a single entry point.
Nothing knows about the whole building yet, or how to find a free spot. A `Floor` owns its spots and can find a free one for a vehicle type. `ParkingLot` owns the floors and is the one entry point: `park()` hands out a ticket and `exit()` takes it back. Each class has one job. The spot knows if it is free, the floor searches its own spots, the lot coordinates the floors. Callers only ever talk to `ParkingLot`. Searching floor by floor is simple but slow for a huge lot. Keeping a set of free spots per type later makes it instant without changing the public methods.
Pull the pricing rule out so it can change without touching parking.
Pricing is stuck inside `exit()`. Weekend rates, flat fees or monthly passes would mean editing and re-testing the parking logic every time. A `PricingStrategy` interface with one method, `fee()`. `HourlyPricing` and `FlatPricing` implement it, and `ParkingLot` is given one when it is created. This is the **Strategy** pattern: the part that changes (how to price) is separate from the part that stays the same (parking and exiting). Weekend pricing is one new class and nothing else changes. A few more small classes. It is worth it because pricing is the rule most likely to change, and each strategy can be tested on its own.
Choose spots by rule, and stop two gates taking the same spot.
Which spot gets picked is hard-wired (first free). And two entry gates asking at the same instant could both be given the same spot. A `SpotAllocationStrategy` picks which free spot to offer (nearest to the entrance, lowest floor, and so on). `ParkingSpot.tryOccupy()` is **atomic**, and `ParkingLot` is the single shared instance for the building. Allocation varies independently of pricing, so it is its own strategy. If two gates race for one spot, `tryOccupy()` lets exactly one win and the loser simply tries the next spot. Locking each spot lets many gates work at once. One big lock around `park()` is simpler but makes every gate wait for every other gate.