There are a set of questions that seem to be commonly-used in interviews and classes when it comes to object-oriented design and analysis. This is one of them; unfortunately, my OOP professor in college never actually gave an answer to it, and so I've been wondering.
The problem is as follows: design a basic set of objects/methods to be used to simulate an elevator bank. What are the objects and their attributes/methods?
For the sake of argument, let us assume that our building has twenty floors; the bottom floor is the lobby, and the second floor connects to the parking garage (therefore, people will enter/exit the building on either the bottom floor or the second floor). There is one elevator bank that services all the floors; there are three elevator shafts in the elevator bank, and one elevator per shaft.
What would be the correct way to model this in an object-oriented model?
First there is an elevator class. It has a direction (up, down, stand, maintenance), a current floor and a list of floor requests sorted in the direction. It receives request from this elevator.
Then there is a bank. It contains the elevators and receives the requests from the floors. These are scheduled to all active elevators (not in maintenance).
The scheduling will be like:
Each elevator has a set of states.
There are additional signals:
EDIT: Some elevators don't start at bottom/first_floor esp. in case of skyscrapers.
min_floor & max_floor are two additional attributes for Elevator.