SOLID Principles: Single Responsibility Principle (SRP)

  • this means that a class should not be loaded with multiple responsibilities and a single responsibility should not be spread across multiple classes or mixed with other responsibilities.
  • The reason is that the more changes requested in the future, the more changes the class needs to apply.
  • Example:
public class Employee{public double CalculatePay(Money money){//logic for payments}
public String reportHours(Employee employee){
//logic for get report for employee}public Employee save(Employee employee){//store employee to the database}}
  • The reportHours() method is specified and used by the human resources department, which reports to the COO.
  • The save() method is specified by the database administrators, who report to the CTO.
Facade pattern

Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system.

and after apply SRP the code will be something like that:

public class Employee{// Employee Data
public class PayCalculator{public double CalculatePay(Money money){//logic for payments}
public class HourReport{public String reportHours(Employee employee){//logic for get report for employee}
public class EmployeeSaver{public Employee saveEmployee(Employee employee){//store employee to database}}



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store