Design a lift panel using classes and OOP concepts

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-04-20

Problem Statement

Designing the Lift Panel System for an elevator inside a building. The system should model the buttons, indicators, and controls that allow passengers to interact with the lift. The design should be object-oriented, extensible, and easy to integrate with a larger Elevator Control System.


Functional Requirements


1.Button Interactions
•Each lift has a panel with:
•Floor Buttons (to request a floor).
•Open/Close Door Buttons.
•Emergency/Alarm Button.
•Pressing a button should trigger the corresponding action/event.
2.Indicators & Display
•Panel should display:
•Current floor.
•Direction of movement (up/down).
•Overload/Error indicators.
3.Event Handling
•When a floor button is pressed: request should be passed to the Elevator Controller.
•When an emergency button is pressed: alarm system should be triggered.
•Duplicate presses for already queued floors should be ignored.
4.State Management
•Buttons should reflect state (pressed/unpressed).
•Indicators should update dynamically based on elevator movement.


Non-Functional Requirements


•Extensibility: Should support advanced features (e.g., touch panel, voice-activated commands).
•Encapsulation: Each panel component should be self-contained.
•Reusability: Should work across multiple elevators.
•Thread Safety: Concurrent button presses should be handled safely.


Design Constraints & Edge Cases


•If multiple passengers press the same floor button → should not duplicate requests.
•Emergency button should override all other requests.
•If elevator is overloaded → ignore new floor button presses until cleared.


Design Hints


•Key Classes / Interfaces:
•LiftPanel → represents the whole panel inside the elevator.
•Button (abstract class/interface).
•FloorButton → mapped to a specific floor.
•DoorButton → open/close doors.
•EmergencyButton → trigger alarms.
•Indicator
•FloorIndicator → shows current floor.
•DirectionIndicator → up/down movement.
•OverloadIndicator.
•Display → central panel screen showing information.
•ElevatorController (external dependency) → receives events from panel.
•Design Patterns:
•Observer Pattern → Panel listens for updates from elevator (floor changes, direction).
•Command Pattern → Each button press issues a command to the controller.
•State Pattern → To manage pressed/unpressed button states.


Example Flow


1.Passenger presses Floor 5 button →
•FloorButton(5) marked as pressed.
•ElevatorController receives request → schedules floor 5 in queue.
2.Passenger presses Emergency Button →
•Sends immediate signal to controller → halts lift, triggers alarm.
3.Elevator moves →
•FloorIndicator updates to show 3 → 4 → 5.
•On reaching floor 5, FloorButton(5) resets to unpressed.


Evaluation Areas


•Proper class hierarchy for buttons.
•Encapsulation of display & indicator logic.
•Correct use of OOP principles (abstraction, polymorphism, inheritance).
•Handling of edge cases (duplicate presses, emergency overrides, overloads).


Solution

Comments