The Single Responsibility Principle (SRP) is the SOLID design principle, attributed to Robert C. Martin, that a class should have only one reason to change. Each module or class is responsible for a single part of the software's functionality. Separating unrelated responsibilities into their own classes keeps a change to one feature from touching unrelated code and keeps unit-test setup simple.

SOLID-Single Responsibility Principle

Details
Full Name

SOLID Single Responsibility Principle (SRP)

Intent:

A class should have only one reason to change. Each module or class should be responsible for a single part of the software’s functionality.

When to Use:

  • A class has multiple unrelated responsibilities

  • Changes to one feature require modifying unrelated code

  • Unit testing requires complex setup due to tangled concerns

Prompt Example:

"Refactore diese Klasse nach dem SOLID-Single Responsibility Principle. Trenne die Verantwortlichkeiten in separate Klassen."