1

I'm reading the book 'Clean Code' by Robert C. Martin. The book said code under this paragraph violates Single Responsibility Principle But I don't know why!

Payroll.java

  Public Money calculatePay(Employee e)
  throws InvalidEmployeeType {
    switch (e.type) {
      case COMISSIONED:
        return calculateCommissionedPay(e);
      case HOURLY:
        return calculateHourlyPay(e);
      case SALARIED:
        return calculateSalariedPay(e);
      default:
        throw new InvalidEmployeeType(e.type);
    }
  }

I think 'calculate pay' only has responsibility for CFO. So, I thought this code doesn't violate SRP. However, the book said it's not. Could you help me, please?

Mint Bee
  • 49
  • 1
  • 3
  • 10

0 Answers0