The problem described can be expressed in a series of if … else if … else … endif statements. An object-oriented version of this idiom is the chain of responsibility design pattern. This pattern defines a chain of receiver objects that have the responsibility of either handling a request or passing it to the next receiver in the chain if one exists. The following class diagram shows a possible implementation of the pattern for this problem:
employee is a class that represents an employee in the company. An employee may have a direct manager that is set with a call to the set_direct_manager() method. Every employee has a ...