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}}




Software engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Ruby on Rails debugging on Visual Studio Code

How to Install WordPress on Windows IIS in 2020? Step-by-Step Tutorial (Part-2)

Sustaining Innovation for the Cloud Market in APAC

Understanding the Trading API

DevOps Automation Tools: Things you should keep in mind

Program 26/1/22_0

How to Synchronize Data from Hive to MaxCompute?

How to Send Emails via Python (the better way), introduction to Red Mail

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
Hussein Reda

Hussein Reda

Software engineer

More from Medium

SOLID Principles

Test-Driven Development — What, How, and Why?

SOLID Principles

Dependency Inversion Principle