Skip to content

Instantly share code, notes, and snippets.

View Alfionte's full-sized avatar

Gabriele Alfionte

  • Arona
View GitHub Profile
@xpepper
xpepper / Single Responsibility Principle.md
Last active March 23, 2023 21:05
Uncle Bob on the Single Responsibility Principle

(from SOLID Principles with Uncle Bob - Robert C. Martin - http://www.hanselminutes.com/145/solid-principles-with-uncle-bob-robert-c-martin)

Single Responsibility Principle, what does it mean? It means that a software module should have one reason to change, then that's what I call a responsibility, a reason to change.

So for example, take a payroll application, if there's an employee class in that payroll application, you could imagine that it might have methods for calculate pay or perhaps another method for print a report, perhaps another method in the employee object for save me to the database, and what's unfortunate about these three methods existing in the same class is that they have all three completely different reasons to change. The payroll, the calculate pay will change if the accountants decides on a new way of calculating pay. The report generator will change if the people who consume the reports want the format of the reports to change. The save function will change if the DBA's decid