🎯 Design Patterns Quick Reference

Real-World Guide to Factory, Strategy, Observer & Singleton Patterns

🏭

Factory

"Creates different things based on what you ask for"

Real-World Analogy

Restaurant kitchen - order by name, kitchen makes it

Problem It Solves

Creating many similar things without knowing all the complex details

Examples
Use When

Many similar types to create
Creation is complex
Need to add new types easily

Don't Use When

Only one type exists
Creation is simple

🔄

Strategy

"Switching between different ways to do the same task"

Real-World Analogy

GPS routes - fastest, scenic, or avoid highways

Problem It Solves

Need different approaches for same goal that you can switch between

Examples
Use When

Multiple ways to do same thing
Need to switch at runtime
Want to avoid messy if/else chains

Don't Use When

Only one approach exists
Approach never changes

📢

Observer

"When something happens, notify everyone who cares"

Real-World Analogy

YouTube subscriptions - upload once, all subscribers notified

Problem It Solves

One event needs to trigger multiple reactions automatically

Examples
Use When

One change affects many objects
Want loose coupling
Listeners join/leave dynamically

Don't Use When

Only one thing needs notification
Direct communication is fine

Singleton

"Ensuring there's only ONE of something"

Real-World Analogy

Company CEO - one leader, everyone refers to same person

Problem It Solves

Need exactly one shared instance that everyone accesses

Examples
Use When

Need exactly ONE instance
Shared resource required
Changes should be universal

Don't Use When

Multiple instances might be needed
"Just to be safe" (misused often!)

🎯 Quick Decision Guide: Which Pattern Do I Need?

Need to CREATE different types? Use 🏭 Factory
Need to SWITCH between methods? Use 🔄 Strategy
Need to NOTIFY multiple objects? Use 📢 Observer
Need EXACTLY ONE shared instance? Use ⭐ Singleton

💡 Key Principles