Design Patterns
What is it?
Design patterns are reusable, named solutions to common software design problems — a shared toolkit of proven approaches.
Explain like I'm 5
Why was it created?
Developers kept solving the same structural problems repeatedly. Patterns were cataloged to share proven solutions and a common vocabulary.
Where is it used?
- Structuring object-oriented code
- Framework and library design
- Code reviews and discussions
- Solving recurring design problems
Why should developers care?
Patterns appear in real codebases and interviews, and knowing them helps you recognize good structures and communicate clearly.
How does it work?
Each pattern describes a problem, a solution shape, and trade-offs. They're grouped into families — creational (how objects are made), structural (how they're composed), and behavioral (how they interact). You apply one when its problem matches yours.
Real-world example
When you need only one shared instance of something, the Singleton pattern names that solution; when creating objects flexibly, the Factory pattern applies.
Common use cases
- Recognizing and naming structures
- Communicating designs
- Solving recurring problems
- Designing flexible code
Advantages
- Proven, reusable solutions
- Shared vocabulary
- Faster design decisions
- Capture trade-offs explicitly
Disadvantages
- Easy to over-apply
- Can add needless complexity
- Forcing a pattern hurts simple code
- Memorizing without understanding misleads
When should you use it?
When a recurring design problem matches a known pattern's intent.
When should you avoid it?
When a simple direct solution works — don't add a pattern just to use one.
Alternatives
Related terms
Interview questions
Beginner
- What is a design pattern?
- Name a common one.
Intermediate
- What are the three families of patterns?
- When is the Factory pattern useful?
Senior
- When does applying patterns become over-engineering?
- How do patterns improve team communication?
Common misconceptions
- "More patterns means better code" — overusing them adds complexity; patterns serve the problem, not the other way around.
- "Patterns are language features" — they're general solution shapes you implement, not built-in constructs.
Fun facts
- The influential 'Gang of Four' book cataloged 23 classic patterns.
- Patterns are grouped as creational, structural, and behavioral.
Timeline
- 1994 — The 'Gang of Four' design patterns book is published
Learning resources
Quick summary
Design patterns are named, reusable solutions to recurring design problems, giving developers proven approaches and shared vocabulary.
Cheat sheet
- Reusable solutions to common problems
- Creational, structural, behavioral families
- Shared vocabulary
- Don't force them where unneeded