What if a tiny typo could crash your whole parking system? Enums save you from that nightmare!
Why Enum usage (VehicleType, SpotType) in LLD? - Purpose & Use Cases
Imagine managing a parking lot system where you have to track different types of vehicles and parking spots manually using plain text or numbers.
Every time you add a new vehicle or spot type, you must remember the exact string or number and ensure consistency everywhere.
This manual approach is slow and error-prone because typos or mismatched values can cause bugs.
For example, writing "car" sometimes and "Car" other times leads to confusion and wrong behavior.
It also makes the code hard to read and maintain, especially as the system grows.
Using enums for VehicleType and SpotType gives a fixed set of named values that the system understands clearly.
This prevents mistakes, makes the code easier to read, and helps the system handle only valid types.
It acts like a checklist that the program follows strictly, avoiding guesswork.
vehicleType = "car" if vehicleType == "car": parkCar()
enum VehicleType { CAR, BIKE, TRUCK }
vehicleType = VehicleType.CAR
if vehicleType == VehicleType.CAR:
parkCar()It enables building reliable and clear systems that handle specific categories without confusion or errors.
In a parking management app, enums ensure that only valid vehicle types like CAR, BIKE, or TRUCK are accepted, preventing wrong inputs and simplifying spot allocation.
Manual string or number codes cause errors and confusion.
Enums provide a fixed, clear set of valid types.
This leads to safer, easier-to-maintain system design.
