Class Diagram for the Elevator System
Learn to create a class diagram for the elevator system problem using the bottom-up approach.
In this lesson, we’ll identify and design the classes, abstract classes, and interfaces based on the requirements that we have previously gathered from the interviewer in our elevator system.
Components of an elevator system
As mentioned earlier, we should design the elevator system using a bottom-up approach. Therefore, we will first identify and design classes of the smaller components like button, door, and floor. Then, we will create the class of the entire elevator control system, which will contain these smaller components.
Button
Button
is an abstract class. There can be two types of buttons i.e., the elevator button and the hall button. The status of the button determines whether the button is pressed or unpressed. We can press the button or check the status of the button through the Button
class.
The ElevatorButton
subclass is inherited from the Button
class and represents the buttons that are inside the elevator. When the elevator button is pressed, it specifies what would be the destination floor of the elevator car or where the passenger wants to go.
Similar to ElevatorButton
, HallButton
is also a subclass of the Button
class. This class represents the buttons that are outside the elevator. This class used the enumeration Direction to specify whether the button is for going up or down. The hall button has two important pieces of information, the floor from where the button is pressed and the direction in which the passenger wants to move.
The UML representation of these classes is shown below:
Elevator panel and hall panel
ElevatorPanel
is a class which is used to represent the complete grid of buttons inside the elevator. In the elevator panel, we will have a list of buttons for selecting the destination floor of the elevator and two buttons for closing and opening the elevator.
While the HallPanel
class represents the buttons that are outside the elevators. The hall panel consists of only two buttons: up and down.
Both the elevator panel and the hall panel are used to take input from the passenger. The representation of both classes is given below:
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.