Skip to content
BENIBIX Learn

SOLID Principles

Development🧩 Programming ConceptsDevelopment Practices

Also known as SOLID, SOLID Design Principles, Single Responsibility Principle, Open-Closed Principle

Five rules for building classes. They keep code easy to change.

Think of it like

Think of it like five rules for toy bricks. You can swap one brick and the tower stays up.

Example

Emma's Report class makes reports and also emails them. Following the first SOLID rule, she splits it in two. Now changing the email code cannot break the reports.

Why it matters

As code grows, changes start to break things far away. SOLID keeps parts apart, so a change stays local.

Definition

SOLID is five rules for designing classes in object-oriented code so they are easy to change. S: each class has one job. O: you can add behaviour without editing old code. L: a child class must work anywhere its parent does. I: keep interfaces small. D: depend on interfaces, not on concrete classes.

Common mistake

Applying all five rules to a tiny script. They help large, long-lived code; in small code they just add layers.

Key takeaways

  1. 1
    One job per class. The S.
  2. 2
    Add, do not edit. The O.
  3. 3
    Lean on interfaces. The I and the D.

Learn it properly