SOLID Principles
Five rules for code that stays easy to change, with the before-and-after code that shows why each one matters.
- Module 4 of 11
- Intermediate
- 8 chapters
- 35 min
SOLID is the shared language for discussing design in code reviews and design interviews. Each principle is shown with code that breaks and the change that fixes it.
What you will be able to do
- Explain cohesion and coupling
- Apply each SOLID principle to real code
- Spot violations in a design and refactor them
- Know when not to apply a principle
Chapters
1. Two Ideas Behind Everything: Cohesion and CouplingCohesion — how closely the parts inside one class belong together. Aim for high cohesion: every method and field serves one3 min2. S: The Single Responsibility Principlethe class name contains "Manager", "Helper", "Utils" or "And";3 min3. O: The Open/Closed PrincipleYou can't close against every possible change. Apply OCP where change has already happened or clearly will (new plans, new question3 min4. L: The Liskov Substitution Principleit may not demand more from callers (stricter inputs — e.g. rejecting values the parent accepts);4 min5. I: The Interface Segregation PrincipleA TV remote with 80 buttons when you only ever use power, volume and channel. Worse: to make a new remote, the manufacturer must wire up all2 min6. D: The Dependency Inversion PrincipleDependency Inversion Principle (DIP): high-level code (business rules) should not depend on low-level code (email, databases); both5 min7. The Friends: DRY, KISS, YAGNI, Law of DemeterTaught step by step, with real output.2 min8. Using SOLID SensiblySOLID is a set of tools for managing change, not rules to maximise. Applying every principle everywhere produces the opposite problem: a2 min
Extras
The Whole StoryThe whole module retold as one story — no new facts, a fast revision of SOLID Principles.RevisionInterview QuestionsReal interview questions on SOLID Principles, answered the way you would say them out loud.Interview prepQuick ReferenceGlossary and cheat sheet for SOLID Principles — the page to reread before an interview.Reference