Design Patterns & SOLID Principles
5 min read.
Master the five SOLID principles and six classic Gang-of-Four design patterns with interactive before/after code examples and a reference gallery.
Think of it this way: SOLID principles are like building codes for software — they do not tell you what to build, but they prevent the structural mistakes that make buildings (and codebases) expensive to repair later. Design patterns are the standard room layouts architects reach for once they know the rules.
Single Responsibility
A class should have only one reason to change.
Before: one class does too much
class Invoice {
calculateTotal(): number { ... }
sendEmailConfirmation(): void {
// sends email — not Invoice's job!
smtp.send(this.email, ...)
}
}After: split into focused classes
class Invoice {
calculateTotal(): number { ... }
}
class EmailService {
sendConfirmation(invoice: Invoice): void {
smtp.send(invoice.email, ...)
}
}Check your understanding
Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.
Name the principle
Sort each statement into the SOLID principle it states.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
Single responsibility
Drop items hereOpen/closed
Drop items hereLiskov substitution
Drop items hereInterface segregation
Drop items hereDependency inversion
Drop items hereQuiz
20 questionsWhat does the S in SOLID stand for, and what problem does it prevent?
Done with this lesson?
Sign in free to keep your progress, streak and quiz scores.