Design Pattern
In one line
A design pattern is a proven, reusable solution to a commonly occurring problem in software design.
In simple words
A design pattern is a general, reusable template for solving a recurring design problem. It is not finished code you copy-paste, but a description of how objects and classes should interact to solve a specific class of problems. Patterns capture the collective experience of many developers so you do not have to reinvent the wheel.
The classic Gang of Four (GoF) book cataloged 23 patterns into three families: creational (how objects are made, e.g. Singleton, Factory), structural (how objects compose, e.g. Decorator, Adapter), and behavioral (how objects communicate, e.g. Observer, Strategy). Each pattern has a name, a problem it solves, and a solution structure.
Using patterns gives your code a shared vocabulary: saying "use a Factory here" instantly communicates intent to other developers. However, patterns should emerge from need — forcing a pattern where a simpler solution works adds unnecessary complexity.
Example
// Singleton pattern — only one instance exists
class Database {
static instance = null;
constructor() {
if (Database.instance) return Database.instance;
this.connected = true;
Database.instance = this;
}
}
const a = new Database();
const b = new Database();
console.log(a === b); // true — same instanceThe Singleton pattern ensures only one Database instance exists. Both new Database() calls return the same object.
Related terms
Related Resources
Related Lessons
- Design Patterns
Learn common design patterns.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.