🧩SOLID Principles
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
Common mistake
Key takeaways
- 1One job per class. The S.
- 2Add, do not edit. The O.
- 3Lean on interfaces. The I and the D.