Design Traffic Light Management System
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-01-22
Problem Statement
Design an OOP-based Traffic Light Management System that controls traffic flow at multiple intersections in a city. The system should handle traffic light states (Red, Yellow, Green), support timing rules, and be extensible to accommodate smart traffic management features such as pedestrian signals, adaptive timing, and emergency vehicle overrides.
Functional Requirements
1.Traffic Lights
•Each traffic light cycles between Red → Green → Yellow → Red.
•Timing of each light (e.g., Red = 60s, Green = 45s, Yellow = 5s) should be configurable.
2.Intersections
•Each intersection may have multiple traffic lights controlling different roads.
•Only one direction can be Green at a time (others must be Red).
3.Pedestrian Crossing
•Support pedestrian lights (Walk/Don’t Walk).
•Pedestrian request buttons can alter timing logic.
4.Emergency Vehicle Handling
•Emergency vehicles (e.g., ambulance, fire truck) should override signals and get Green priority.
5.System Management
•Central system to monitor and update traffic lights.
•Ability to add/update/remove intersections dynamically.
Non-Functional Requirements
•Extensibility → Support new rules (e.g., adaptive traffic control based on congestion).
•Scalability → Manage hundreds of intersections.
•Reliability → Ensure no conflicting Green signals at an intersection.
•Maintainability → Easy to adjust timings, add sensors, or override rules.
Design Hints (OOP + Patterns)
•Core Classes/Interfaces:
•TrafficLight → state (Red/Green/Yellow), timer, transition logic.
•PedestrianSignal → state (Walk/Don’t Walk).
•Intersection → collection of traffic lights, control logic.
•TrafficLightController → manages transitions & coordination.
•EmergencyOverrideService → handles priority override logic.
•CentralSystem → manages all intersections, configurations.
•Design Patterns:
•State Pattern → for traffic light state transitions.
•Observer Pattern → central system monitors lights.
•Strategy Pattern → for different timing algorithms (fixed, adaptive, emergency).
•Singleton → for the central system managing global traffic.
✅ Example:
"Design a Traffic Light Management System. Model traffic light states and timing using classes and OOP principles. Ensure the design supports multiple intersections, pedestrian signals, and emergency overrides. Show how you would extend it for adaptive traffic management."