LLD-5 Elevator System
In this article, we will discuss and design an Elevator system. Honestly, I feel it's a bit complex problem to design 👀, So I will put down my thoughts and ideas while designing the same.🥸
Requirements Gathering and Clarification:
- An elevator is present in a building.
- The building may have n number of floors.
- The building may have any number of elevators.
- Any number of elevators can be added or removed based on the need.
- All floors have elevator panels.
- Panels consist of buttons (the external side) indicating the direction the user wants to go.
- An elevator car has buttons on the internal side, indicating which floor the user wants to go to.
- The elevator moves in such a way that there is minimum response time.
- A person can enter the elevator only when it is stopped and the doors are open.
- The elevator's chosen strategy should be dynamic.
- Elevator moving strategy should be dynamic.
- A dispatcher is responsible for gathering requests from buttons on both internal and external sides.
- A panel controller is mainly responsible for choosing a lift based on the strategy provided.
- We should maintain the top floor and the lowest floor number.
Class Identification and Class Diagram:
From the requirements, we can identify the below classes.
- Building
- Floor
- External Panel
- Elevator Car
- Internal Buttons
- Door
- Elevator System
Following are the enums that we can use
- Direction: Upside/ Downside
- Request Type: Internal Request/ External Request
- Status: Moving/ Idle/ Stopped/ Not Available/ Open/ Closed
The class Diagram is as under:
Code Explanation:
- Let’s discuss about elevator controller, whose main responsibility is to control the elevator functionality.
The elevator controller involves:
1) upsideReq: requests for going upside.
2) downsideReq: requests for going downside.
3) elevatorMovingStrategy: strategy using which elevator moves to different floors.
4) elevator: an object to the elevator
- Now, let's discuss about external panel controller
External Panel Controller involves:
1) elevatorChoosingStrategy: a strategy to find which elevator to choose to go to some particular floor.
2) externalPanel: an object to the external button panel.
- Now let’s discuss about elevator system. Elevator system involves
1) elevatorControllers: List of elevator controllers which regulate each elevator.
2) externalPanelControllers: List of external panel controllers that send requests from the floor whether to upside or downside.
References:
GitHub Code Repo ✍️: https://github.com/Akhilesh53/Design/tree/main/Elevator
Follow for more on LinkedIn ✌🏻.