Single Responsibility Principle

Dated Sep 13, 2026; last modified on Sun, 13 Sep 2026

A class should have one reason to change. For example,

public class Report
{
  public string GenerateContent() { ... }
  public void PrintToPdf() { ... }
  public void SaveToFile() { ... }
}

… violates this principle because content generation, PDF formatting, and file storage are all in one place.

What defines “reason”? Do reasons map to user-facing requirements?

Instead, split the responsibilities into separate classes:

public class Report
{
  public string GenerateContent() { ... }
}

public class PdfPrinter
{
  public void Print(Report report) { ... }
}

public class FileStorage
{
  public void Save(string content) { ... }
}

WebContents, Chromium’s class that “renders web content (usually HTML) in a rectangular area”, contains 200+ pure virtual methods!

  1. Design Principles | Hello Interview Low Level Design. www.hellointerview.com . Accessed Sep 13, 2026.
  2. web_contents.h - Chromium Code Search. source.chromium.org . Accessed Sep 13, 2026.