Catalog

22 patterns, grouped by purpose.

Each card opens a tutorial: problem → step-by-step solution → structure → runnable demo → when not to use it.

0/22 marked as learned22 results
01
Behavioral

Template Method

Pin down the order of an algorithm's steps in exactly one place and leave open only the steps that can vary. The GoF version opens them through inheritance; the modern JS version opens them through hooks/callbacks.

●○○·12 min·8 steps
02
Behavioral

Strategy

Pull an algorithm that keeps changing out into separate objects (the "strategies"), and let the object that uses it pick one at runtime instead of hard-coding the choice with if/else.

●○○·12 min·8 steps
03
Behavioral

Observer

Let many parties subscribe to "listen" to an event source; when the source changes state, it notifies all of them without knowing who is listening or how many there are.

●●○·14 min·8 steps
04
Creational

Factory Method

Wrap the "which class do I new up" decision in a single method or function, so the call site only declares what it needs, and the choice of implementation is made at runtime by a subclass, config or registry.

●●○·11 min·8 steps
05
Creational

Singleton

Guarantee that the whole process has exactly one instance, and expose a single door for getting it. In JS, ES modules already handle the "one instance" part, so the real value of the pattern lies elsewhere: controlling *when* the instance is born, *with which arguments*, and *who is allowed to replace it in tests*.

●○○·12 min·8 steps
06
Structural

Decorator

Wrap an object in another object with exactly the same interface to add responsibilities (log, retry, cache, validate) around the call — the client does not know, and does not need to know, that it is holding the wrapped version.

●●○·15 min·8 steps
07
Behavioral

Iterator

Traverse a collection without exposing how it is stored: array, map, tree, or pages of remote data. The outside only sees `next()` returning `{ value, done }`, and `for...of` runs on exactly that contract.

●●○·13 min·8 steps
08
Structural

Adapter

Insert a translation layer at the boundary: it takes data and calls in someone else's shape (a third-party API, a legacy module, a DTO) and returns exactly your internal contract, so the core of the system only ever knows its own data types.

●●○·13 min·8 steps
09
Behavioral

Command

Wrap a "thing to do" (its parameters, the object it acts on, how to do it, how to undo it) in an object, so you can queue it, log it, send it somewhere, retry it, replay it or undo it — instead of calling a function and losing all trace of it.

●●○·14 min·8 steps
10
Structural

Composite

Give leaves and branches one shared interface in which every operation is defined recursively: a leaf answers directly, a branch answers by asking its children. Calling code can then handle a single element and an entire tree with exactly the same code.

●●○·13 min·8 steps
11
Structural

Facade

Collapse a subsystem's scattered API into ONE API phrased in business language: the client calls one function, and call order, parameters, retries and logging are the facade's job.

●○○·11 min·8 steps
12
Behavioral

State

Package each state of an object as its own set of behaviour, so the state itself decides which actions are valid and which state it moves to next — instead of making every other place guess from `status` with if/else.

●●○·14 min·8 steps
13
Creational

Builder

Construct an object with many parameters (mostly optional) through an intermediate object that accumulates them step by step, then commit in build() — the one place that validates every constraint and produces a final object that is guaranteed to be valid.

●●○·14 min·8 steps
14
Creational

Prototype

Create new objects by copying an existing template object instead of rebuilding an expensive configuration from scratch — and in JS/TS, the hard part isn't "cloning" but cloning *correctly*: shallow or deep, and whether the prototype, Maps/Sets, and circular references survive.

●●○·14 min·8 steps
15
Structural

Proxy

Put a stand-in in front of the real object: the client holds the proxy and can't tell the difference, while the proxy decides when the real object gets touched, what gets touched, and whether it gets touched at all.

●●●·14 min·8 steps
16
Creational

Abstract Factory

A single factory creates an entire family of related products (Button + Input + Card of the same theme), so the client can no longer accidentally mix products from two different families.

●●●·13 min·8 steps
17
Structural

Bridge

Split a class that carries two independent axes of change into two separate hierarchies joined by composition (one side holds an interface reference to the other), so either side can gain new members without touching the other.

●●○·14 min·8 steps
18
Behavioral

Chain of Responsibility

Pass a request through a series of handlers: each one either answers it and stops the chain, or calls `next` to push it along. Whoever sends the request doesn't need to know who will handle it.

●●○·14 min·8 steps
19
Structural

Flyweight

Share the duplicated state across many objects instead of giving each object its own copy: the common part lives in one object reused by key, and the per-object part (external state) is passed in at the point of use.

●●○·12 min·8 steps
20
Behavioral

Mediator

Pull all the communication logic between a group of objects into exactly one place, so the objects only talk to that place and never to each other.

●●●·15 min·8 steps
21
Behavioral

Memento

Capture an object's state into a sealed package you can restore later, without forcing the object to expose its internal fields to whoever holds that package.

●●○·13 min·8 steps
22
Behavioral

Visitor

Add new operations to a fixed tree of nodes without modifying any node: each node only declares "what kind I am", and all of the operation's logic lives in the visitor.

●●●·16 min·8 steps

The full path

The order below goes from easiest to hardest and from most to least useful in real web projects. Go one by one, ~10-15 minutes each.

  1. Template MethodPin down the order of an algorithm's steps in exactly one place and leave open only the steps that can vary. The GoF version opens them through inheritance; the modern JS version opens them through hooks/callbacks.
  2. StrategyPull an algorithm that keeps changing out into separate objects (the "strategies"), and let the object that uses it pick one at runtime instead of hard-coding the choice with if/else.
  3. ObserverLet many parties subscribe to "listen" to an event source; when the source changes state, it notifies all of them without knowing who is listening or how many there are.
  4. Factory MethodWrap the "which class do I new up" decision in a single method or function, so the call site only declares what it needs, and the choice of implementation is made at runtime by a subclass, config or registry.
  5. SingletonGuarantee that the whole process has exactly one instance, and expose a single door for getting it. In JS, ES modules already handle the "one instance" part, so the real value of the pattern lies elsewhere: controlling *when* the instance is born, *with which arguments*, and *who is allowed to replace it in tests*.
  6. DecoratorWrap an object in another object with exactly the same interface to add responsibilities (log, retry, cache, validate) around the call — the client does not know, and does not need to know, that it is holding the wrapped version.
  7. IteratorTraverse a collection without exposing how it is stored: array, map, tree, or pages of remote data. The outside only sees `next()` returning `{ value, done }`, and `for...of` runs on exactly that contract.
  8. AdapterInsert a translation layer at the boundary: it takes data and calls in someone else's shape (a third-party API, a legacy module, a DTO) and returns exactly your internal contract, so the core of the system only ever knows its own data types.
  9. CommandWrap a "thing to do" (its parameters, the object it acts on, how to do it, how to undo it) in an object, so you can queue it, log it, send it somewhere, retry it, replay it or undo it — instead of calling a function and losing all trace of it.
  10. CompositeGive leaves and branches one shared interface in which every operation is defined recursively: a leaf answers directly, a branch answers by asking its children. Calling code can then handle a single element and an entire tree with exactly the same code.
  11. FacadeCollapse a subsystem's scattered API into ONE API phrased in business language: the client calls one function, and call order, parameters, retries and logging are the facade's job.
  12. StatePackage each state of an object as its own set of behaviour, so the state itself decides which actions are valid and which state it moves to next — instead of making every other place guess from `status` with if/else.
  13. BuilderConstruct an object with many parameters (mostly optional) through an intermediate object that accumulates them step by step, then commit in build() — the one place that validates every constraint and produces a final object that is guaranteed to be valid.
  14. PrototypeCreate new objects by copying an existing template object instead of rebuilding an expensive configuration from scratch — and in JS/TS, the hard part isn't "cloning" but cloning *correctly*: shallow or deep, and whether the prototype, Maps/Sets, and circular references survive.
  15. ProxyPut a stand-in in front of the real object: the client holds the proxy and can't tell the difference, while the proxy decides when the real object gets touched, what gets touched, and whether it gets touched at all.
  16. Abstract FactoryA single factory creates an entire family of related products (Button + Input + Card of the same theme), so the client can no longer accidentally mix products from two different families.
  17. BridgeSplit a class that carries two independent axes of change into two separate hierarchies joined by composition (one side holds an interface reference to the other), so either side can gain new members without touching the other.
  18. Chain of ResponsibilityPass a request through a series of handlers: each one either answers it and stops the chain, or calls `next` to push it along. Whoever sends the request doesn't need to know who will handle it.
  19. FlyweightShare the duplicated state across many objects instead of giving each object its own copy: the common part lives in one object reused by key, and the per-object part (external state) is passed in at the point of use.
  20. MediatorPull all the communication logic between a group of objects into exactly one place, so the objects only talk to that place and never to each other.
  21. MementoCapture an object's state into a sealed package you can restore later, without forcing the object to expose its internal fields to whoever holds that package.
  22. VisitorAdd new operations to a fixed tree of nodes without modifying any node: each node only declares "what kind I am", and all of the operation's logic lives in the visitor.