For the following problem statement, I design following classes. Can you please tell me if this is the correct implementation or if there can be a better one?
Let's say there is call center with three levels of employees: fresher, technical lead (TL), product manager (PM). There can be multiple employees, but only one TL or PM. An incoming telephone call must be allocated to a fresher who is free. If a fresher can’t handle the call, he or she must escalate the call to technical lead. If the TL is not free or not able to handle it, then the call should be escalated to PM. Design the classes and data structures for this problem.
using System;
using System.Linq;
using System.Collections.Generic;
namespace TestNS
{
public class Employee
{
public string Name { get; set; }
public bool IsFree { get; set; }
public Employee Manager { get; set; }
}
public class Call
{
public Employee AllocatedTo { get; set; }
public bool HandleCall()
{
AllocatedTo.IsFree = false;
bool isHandled = false;
// Write custom logic to handle the call & set the value of isHandled
if (isHandled)
{
AllocatedTo.IsFree = true;
}
return isHandled;
}
public void Escalate()
{
AllocatedTo = AllocatedTo.Manager;
HandleCall();
}
}
public class CallManager
{
List<Employee> fresherList = new List<Employee>();
public void CreateEmployeeList()
{
Employee PM = new Employee() { Name = "PM1", IsFree = true };
Employee TL = new Employee() { Name = "TL1", IsFree = true };
TL.Manager = PM;
fresherList = new List<Employee>();
fresherList.Add(new Employee() { Name = "F1", Manager = TL, IsFree = true });
fresherList.Add(new Employee() { Name = "F2", Manager = TL, IsFree = true });
fresherList.Add(new Employee() { Name = "F3", Manager = TL, IsFree = true });
fresherList.Add(new Employee() { Name = "F4", Manager = TL, IsFree = true });
fresherList.Add(new Employee() { Name = "F5", Manager = TL, IsFree = true });
fresherList.Add(new Employee() { Name = "F6", Manager = TL, IsFree = true });
}
private Employee FindFreeEmployee()
{
Employee e = null;
foreach (Employee emp in fresherList)
{
if (emp.IsFree)
{
e = emp;
break;
}
}
return e;
}
public void ReceiveAndAllocateCall(Call call1)
{
call1.AllocatedTo = FindFreeEmployee();
call1.HandleCall();
}
}
}
CallAllocator
orCallRouter
would be better names. \$\endgroup\$