SOLID Principles
Each principle shown as a bad example first, then what actually goes wrong, then a version that is easier to change.
Lessons in order
- 01Intermediate 14 min
Single Responsibility — One Reason to Change
A class should have one reason to change. See a class doing four jobs, what breaks because of it, and the version that survives change.
- 02Intermediate 13 min
Open/Closed — Extend Without Editing
Add new behaviour by adding code, not by modifying code that already works. See the growing if/elif chain and the version that replaces it.
- 03Intermediate 14 min
Liskov Substitution — Subclasses Must Fit
Any subclass must work anywhere its parent works. See the classic broken hierarchy, why it fails, and how to model it correctly.
- 04Intermediate 12 min
Interface Segregation — Small Contracts
No class should be forced to implement methods it does not need. See a fat interface, the empty methods it produces, and the split that fixes it.
- 05Intermediate 14 min
Dependency Inversion — Depend on Contracts
High-level logic should not depend on low-level details. Learn how injecting dependencies makes code testable, swappable and honest.