Wednesday, March 11, 2015

[LLD] Design Elevator

enum LiftDirection
{
      UP = 0,
      DOWN,
      STOP
}

enum LiftState
{
      ON = 0,
      OFF
}

enum DoorState
{
      OPEN = 0,
      CLOSE
}

class Task
{
      int floor;
      LiftDirection direction;
}

class ElevatorState
{
      int floor;
      LiftDirection direction;
      LiftState state;
}

class OutsideButtonListener
{
      listen();
}

class OutsideButton
{
      OutsideButtonListener listener;
      int floor;
      bool direction;
      void createTask();
      bool sendTask();
      void listenForUserInput();
}

class ControllerListener
{
      queue<Task*> tasks;
      void listen();
}

class CentralController
{
private:
      ControllerListener m_listener;
      vector<Elevator> m_elevators;
      int totalFloors;
      void AssignTask(Task* task);
      void TaskDone(Task* task);
      set<Task*> AssignedTaks;
      void MonitorAssignedTasks();

public:
      void ListenForTasks();
}

class Instantiator
{
      InitController();
      CentralController *controller
}

class ElevatorTask
{
      int floor;
      CentralController* controller
      friend bool operator < (ElevatorTask t1, ElevatorTask t2)
      {
        return t1.floor < t2.floor;
      }
}

class ElevatorDoor
{
      DoorState state;
      bool open();
      bool close();
      bool isClosed();
      DoorState getState();
}

class Button
{
      Action action;
      void setAction(Action ac);
      Action getAction();  
}

class KeyPad
{
      vector<Button> buttons;
      getAction(int index);
}

class KeyPadListner
{
      queue<int>q_indices;
      void listen();
}

class KeyPadController
{
      KeyPadListner listner;
      void waitForInput();
      bool doAction(int index);
      KeyPad pad;
}

class Elevator
{
private:
      int floor;
      ElevatorDoor door;
      Direction direction;
      KeyPadController keyPadController;
      ElevatorState state;
      set<ElevatorTask> assignedTasks;
      void ProcessTasks();

public:
      bool AssignTask(Task* task, CentralController* controller);
      ElevatorState getState();
}

No comments:

Post a Comment