🦄

Claudio Petrini

SOLID #1: Single responsibilty

Single responsibilty principle

Name is inappropriate, it doesn't mean that every module should do just one thing (there is a principle for that but it's not SRP).

Definition

A module should be responsibile to one, and only one, actor.

By module we mean a source file/set of functions which implements some business logic.

By actor we mean a group of people who require a specific change.

Example

As an example having a class which is able to write from the database (eg: through a save method) and run an algorithm based on those information is violating the SRP (eg: through a doPayroll).

The reason for that is that the main actor of the save method is a DBA while the doPayroll method main actor is probably the CFO.

Symptoms of violating it

  1. Accidental duplication
  2. Merges causing conflicts

Solution

Separate code that supports different actors.

Facade pattern can help.

References

  • Robert C. Martin, Clean Architecture

Made with love in Rome.