---
title: Single Responsibility
description: A class should have only one reason to change.
tokens: ~208
---

# Single Responsibility

A class should have one reason to change. If a class mixes multiple concerns, split them.

## Example

This `Report` class handles content, PDF formatting, and file storage all in one place:

```typescript
class Report {
  generateContent(): string {
    return "content";
  }

  printToPdf(): void {
    // PDF formatting
  }

  saveToFile(): void {
    // file I/O
  }
}
```

Split into three classes, each with one job:

```typescript
class Report {
  generateContent(): string {
    return "content";
  }
}

class PdfPrinter {
  print(report: Report): void {
    // PDF formatting
  }
}

class FileStorage {
  save(content: string): void {
    // file I/O
  }
}
```

Now when the PDF library changes, you only touch `PdfPrinter`. When you switch from files to a database, you only modify `FileStorage`. Each change is isolated.