Call center dispatch using object-oriented Python
Segragated the responsilibites of call center into call center and employee
from abc import ABCMeta, abstractmethod
from random import random


class CallCenter(metaclass=ABCMeta):
    &quot;&quot;&quot;
    A call center class that will be inherited from by the director

    Attributes:
        name: Name of the employee
        number: Mobile phone number of the employee
        level: Define level of the employee - respondent, manager or director
    &quot;&quot;&quot;

    @classmethod
    def dispatchCall(self, cls):
        return cls.answerCall()


class Employee(metaclass=ABCMeta):

    def __init__(self, name, number, level):
        self.name = name
        self.number = number
        self.level = level

    def canEmployeeHandle(self):
        canHandle = random()
        if canHandle &gt; 0.5:
            return True
        else:
            return False

    def isEmployeeBusy(self):
        busy = True if random() &lt;= 0.5 else False
        return busy


    @abstractmethod
    def answerCall(self):
        &quot;&quot;&quot;Print a string indicating that this employee is currently
        answering the call or propogate up the chain&quot;&quot;&quot;
        pass



class Director(Employee):
    &quot;&quot;&quot;
    A class definition for the director who will be the third in chain
    to answer the call
    &quot;&quot;&quot;

    def answerCall(self):
        print(&quot;The director is now on call with you&quot;)


class Manager(Director):
    &quot;&quot;&quot;
    A class definition for the manager who will be the second in chain to
    answer the call
    &quot;&quot;&quot;

    def answerCall(self):
        if not self.isEmployeeBusy() and self.canEmployeeHandle():
            print(&quot;The manager is answering your call&quot;)
        else:
            print(&quot;Manager is busy, escalating the call to the Director&quot;)
            super(Manager, self).answerCall()


class Respondent(Manager):
    canHandle = random()  # class variable to check if respondent can handle call
    &quot;&quot;&quot;
    A class definition for the respondent who will be the first in chain
    to answer the call
    &quot;&quot;&quot;

    def answerCall(self):
        if not self.isEmployeeBusy() and self.canEmployeeHandle():
            print(&quot;The respondent is answering your call&quot;)
        else:
            print(&quot;Employee is busy, escalating the call to the Manager&quot;)
            super(Respondent, self).answerCall()


if __name__ == &quot;__main__&quot;:
    director = Director(&quot;Alex&quot;, &quot;+17654736791&quot;, &quot;director&quot;)
    manager = Manager(&quot;Unai&quot;, &quot;+331577285782&quot;, &quot;manager&quot;)
    respondent = Respondent(&quot;Mark&quot;, &quot;+16574872817&quot;, &quot;respondent&quot;)
    CallCenter.dispatchCall(respondent)
    enter code here