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 we previously gathered from the interviewer in our elevator system.
Components of an elevator system
As mentioned, we will design the elevator system using a bottom-up approach. Therefore, we will first identify and design classes for the smaller components like Button
, Door
, and Floor
. Then, we will create the larger components—ElevatorCar
, Building,
and finally the overall ElevatorSystem
—composed of or aggregates the smaller ones.
Button
Button
is an abstract class. There can be four types of buttons: the door button, the elevator button, the hall button, and the emergency stop button. The status of the button determines whether it is pressed or unpressed. We can press the button or check its status through the Button
class.
The ElevatorButton
subclass is inherited from the Button
class and represents the buttons inside the elevator. When the elevator button is pressed, it specifies 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.
Furthermore, there’s an EmergencyButton
class that also inherits the behavior of the abstract Button
class. This class responds to the passengers call when they press the emergency button. It alerts the support team to take prompt action and refrains other passengers from using the elevator car.
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, two buttons for closing and opening the elevator, and an emergency stop button.
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:
Number of buttons in the elevator panel = Number of floors + 3
Number of buttons in the hall panel = 2
Display
Every elevator has a display to represent the current floor number and direction (up or down) of an elevator. It also gives information about the capacity of the elevator. So we will use the Display
class which represents this ...