Strategy Pattern
ELI5 — The Vibe Check
You're writing a sorter and want to sort by price, name, or date depending on user choice. Instead of one giant if/switch block, you create separate 'strategy' objects (SortByPrice, SortByName, SortByDate) and swap them in. The code using the sorter doesn't care which strategy is active — it just calls .sort(). Easy to add new strategies without touching existing code.
Real Talk
undefined
When You'll Hear This
undefined
Related Terms
Decorator Pattern
You have a Coffee object. You want Coffee with Milk. Coffee with Sugar. Coffee with Milk and Sugar. With inheritance you'd need four classes.
Factory Pattern
You want to create a 'notification' object but it might be an EmailNotification, SMSNotification, or PushNotification depending on user preferences.
Observer Pattern
Think of a newsletter. You (the publisher/subject) publish content. Your subscribers (observers) automatically get notified when new content arrives.