+++ +++

Single Responsibility

  • The class only have one reason to change
class Payroll {
  payFor(employee: Employee) {}
}

class Employee {
  CalcPay() {}
  ReportHours() {}
  WriteEmploye() {}
}
  • How many reason does this class have to change ?
  • How many sources of change ? Then the Employee class should have 3 different responsibilities. 3 methods should be long 3 classes
class Payroll {
  payFor(employee: Employee) {}
}

class Employee {
  CalcPay() {}
}

class ReportWrite {
  writeReport(employee: Employee) {}
}

class EmployeeRepository {
  save(employee: Employee) {}
}