Why this matters
- These five names come up in every design discussion and most interviews, and reciting the acronym without an example is transparently shallow.
- Each principle has a concrete code smell attached, which makes them usable while you type rather than only during review.
- Applied mechanically they produce over-engineered code, so knowing when not to apply one is part of knowing them.
The five at a glance
Single responsibilityOne reason to change
Open / closedExtend, do not edit
Liskov substitutionSubtype keeps the promise
Interface segregationSmall, focused contracts
Dependency inversionDepend on abstractions
ResultSwappable, testable units
Single Responsibility
The question: if this class had to change, how many different reasons could cause it?
A class should have one reason to change — one group of stakeholders whose decisions affect it.
Loading compiler…
Loading compiler…
Open/Closed
The question: to add a new case, do I have to edit existing code or only add new code?
Open for extension, closed for modification. The smell is a growing if/else or switch on a
type.
Loading compiler…
Loading compiler…
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 5 sections
- Liskov Substitution
- Interface Segregation
- Dependency Inversion
- Three more worth the same attention
- Common misreadings
Test yourself
Answer these before moving on — recall is what makes it stick.