Good question.
- It would make sense to keep the
fireEmployee(Employee emp)method fireEmployee(Employee emp) inside ManagertheManagerclass only if ManagerManagermaintains a list of employees reporting to him and is allowed to fire only those employees who report to him... in which case "emp"theemppassed as the parameter to this method would have to be one of the employees reporting to him. This way, when an employee is fired we would also need to update the list of employees reporting to that manager which would amount to a change in the state of the Manager object, and hence it would make perfect sense for the fireEmployeefireEmployeemethod to be a part of ManagertheManagerclass, as per OOP principles. - You could instead keep this method directly inside employeethe
Employeeclass with ManagerIdaManagerIdas method-parameter, i.e. fireEmployee(string managerId)fireEmployee(string managerId)... Let EmployeetheEmployeeclass also have a property named empManagerIdempManagerId, which would store employee-IdtheManagerIdof his manager. When the method fireEmployeefireEmployeeis called, the client would supply the manager-id of the manager responsible for firing him. This method of EmployeetheEmployeeclass would then validate that the managerIdmanagerIdpassed as a parameter should be the same as the id of his manager i.e. empManagerIdempManagerId
Hope this helps.