Amazon Interview Question
SDE1sTeam: Search
Country: United States
Interview Type: In-Person
I didn't look at the whole design, just a few things that popped out to me:
1. I would take out the "STATIONARY" from the enum and have a isMoving boolean. The reason is that the elevator may stop to let people in and out, but it still has a direction. In your design, you cannot represent this.
2. I wouldn't use a Person class nor keep track of the persons. Think about a real elevator. Does it know who or even how many persons are in it?
Here is my attempt at OO design. Main classes are: Elevator, Request and Person. Request is an abstract class and the classes that implement/extend it are upRequest, downRequest, emergencyExitRequest and whatever you want. ElevatorSystem is the driver class. My design closely resemble the strategy pattern as I am choosing the serviceRequest implementation at runtime.
Haven't thought about an algorithm to service requests efficiently. Will do it later.
Sorry for taking liberties with C++ syntax.
- Epic_coder June 16, 2013