I am very confused about how to determine that one method has one responsibility, performed in the same way as the following code from the Clean Code book
public Money calculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: return calculateCommissionedPay(e); case HOURLY: return calculateHourlyPay(e); case SALARIED: return calculateSalariedPay(e); default: throw new InvalidEmployeeType(e.type); } }
As the author stated in this code fragment: "... obviously does more than one. Thirdly, it violates the principle of single responsibility (PSA), since there is more than one reason for changing it. " At first glance in the code, I thought that it turned out that the method violates SRP, because if there is a change in the code, it will be a switch statement only if there is an added employee type, but as I try to understand this method, I came up with a hypothesis about why it violates this principle.
My hypothesis is that since the method name is calculatePay(Employee e) , the only responsibility of this method is to calculate payments, as the name of the method is suggested, but since there is a switch inside the method for filtering type Employee this now filtering is different or another responsibility violates SRP I do not know if I understood correctly.
source share