Single Responsibility Principle (SRP)

The Single Responsibility Principle is one of the five SOLID principles for object-oriented programming and software design. It states that a class, module, or function should have only one reason to change, meaning it should have just one responsibility or purpose.

Key aspects of SRP

Example

Imagine a program managing books in a library. According to SRP:

Each class has its own responsibility, and modifying one (e.g., adding a new report format) doesn't affect the others.