In a parking lot system designed to handle various vehicle categories and flexible fee structures, which design principle or pattern most effectively enables adding new vehicle categories and pricing models without altering existing code?
hard🔁 Replacement Q9 of Q15
OOP & Design Patterns - Design a Parking Lot - LLD with OOP (Classes, Patterns, Extensibility)
In a parking lot system designed to handle various vehicle categories and flexible fee structures, which design principle or pattern most effectively enables adding new vehicle categories and pricing models without altering existing code?
AHardcode pricing logic inside the Vehicle classes to tightly couple pricing with vehicle behavior.
BImplement all vehicle types and pricing rules directly within the ParkingLot class for centralized control.
CUse inheritance to create subclasses for each vehicle and pricing type, modifying base classes as needed.
DUse the Strategy pattern combined with interfaces for vehicles and pricing to allow independent extension.
Step-by-Step Solution
Solution:
Step 1: Identify extensibility needs
The system must allow new vehicle types and pricing rules without modifying existing classes.