Amazon Interview Question
SDE-2sCountry: United States
Interview Type: In-Person
I believe a value to the 'supervisor' or 'senior' in the employee would solve this problem. An interface that would have a few methods to 'forwardCall(Employee.Supervisor emp)' would make things look better.
public class Employee implements Call{
Employee supervisor;
String fName;
String lName;
...
public Employee(String fName, String lName, Employee supervisor)
{ this.fName = fName; this.lName = lName; this.supervisor = supervisor;}
public transferToSupervisor(Employee sup)
{
//Code to transfer call
}
public interface Call{
public void answerCall();
...
public void transferToSupervisor(Employee supervisor);
}
Not sure about this answer, feedback appreciated.
Usually such a requirement is handled by Chain of Command Design Pattern.
- teji.catia March 09, 2017