elevator-simulation
Problem statement
Simplified elevator simulation to implement abstract method in object oriented design.
Solution
Summary
The solution has been deployed on Github pages, link. Javascript prototypes have been used to define classes, their properties and methods. The solution is generalized, to n floors and m elevators.
The implementation is restricted to floor buttons only, and jobs are given to idle elevators only.
OOP design
There are 4 classes defined in this implementation. Their properties and methods are detailed below.
-
Controller
This is the main controller/logic class, responsible for defining n floors and m elevators. The Controller class also defines an abstract method buttonPressed which is defined later in the Button class. Job requests are handled with the handleRequest method.
-
Button
This class defines a floor button, which inherits from the Controller class and defines the buttonPressed capability of the abstract method.
-
Floor
This class defines a floor, with characteristics of having 2 buttons (upButton and downButton) and an identifier number, floorNum.
-
Elevator
This class defines an elevator, with characteristics of current idleFloor and movement of direction, which are typically displayed on the elevator status screens. In addition, there is an identifier number, elevatorNum.
The isEligible method checks whether the elevator is fit to take up a job, while the assignJob method takes a job and moves the elevator accordingly.