Single Responsibility Principle (SRP) is a design principle stating that a class or function should have only one job or reason to change. When each unit of code does exactly one thing, it becomes much easier to understand, modify, and test in isolation.
It has a direct connection to testability: clear, focused responsibilities make it straightforward to write and maintain tests because failures point to a single, well-defined concern rather than a tangle of mixed logic.
SRP is one of the SOLID principles and closely related to DRY.
For example, a function that both fetches data and formats it for display violates SRP; splitting these into two functions makes each independently testable.
It has a direct connection to testability: clear, focused responsibilities make it straightforward to write and maintain tests because failures point to a single, well-defined concern rather than a tangle of mixed logic.
SRP is one of the SOLID principles and closely related to DRY.
For example, a function that both fetches data and formats it for display violates SRP; splitting these into two functions makes each independently testable.