Last Updated: November 21, 2025
Design Patterns
Software design patterns
Creational Patterns
| Item | Description |
|---|---|
Singleton
|
Single instance of a class |
Factory
|
Create objects without specifying class |
Abstract Factory
|
Families of related objects |
Builder
|
Construct complex objects step-by-step |
Prototype
|
Clone existing objects |
Structural Patterns
| Item | Description |
|---|---|
Adapter
|
Interface between incompatible classes |
Bridge
|
Separate abstraction from implementation |
Composite
|
Tree structure of objects |
Decorator
|
Add behavior dynamically |
Facade
|
Simplified interface to complex system |
Proxy
|
Placeholder for another object |
Behavioral Patterns
| Item | Description |
|---|---|
Observer
|
Subscribe to events |
Strategy
|
Interchangeable algorithms |
Command
|
Encapsulate requests as objects |
State
|
Change behavior based on state |
Chain of Responsibility
|
Pass request along chain |
Iterator
|
Access elements sequentially |
Mediator
|
Centralized communication |
Singleton Example
class Singleton {
private static instance: Singleton;
private constructor() {}
static getInstance(): Singleton {
if (!Singleton.instance) {
Singleton.instance = new Singleton();
}
return Singleton.instance;
}
}
// Factory Example
interface Product {
operation(): string;
}
class ConcreteProductA implements Product {
operation(): string {
return 'Product A';
}
}
class Factory {
createProduct(type: string): Product {
if (type === 'A') return new ConcreteProductA();
throw new Error('Invalid type');
}
}
💡 Pro Tips
Quick Reference
Reusable solutions to common problems