IntermediateAbout 16 min

    Design Patterns & SOLID Principles

    Read the full article on Substack

    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

    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 here

    Open/closed

    Drop items here

    Liskov substitution

    Drop items here

    Interface segregation

    Drop items here

    Dependency inversion

    Drop items here
    5 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    What 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.

    Keep going