← Back to design patterns map
Design Pattern

Decorator

Wrap an object to add behavior without changing the original class.

structural

Visual Diagram

Base service
-> Auth wrapper
-> Log wrapper
-> Cache wrapper

When To Use

  • ->Adding logging, caching, or auth around services
  • ->Express-style middleware layers
  • ->Extending behavior without subclass explosion
Used in: Express middleware, NestJS decorators, service wrappers
decorator.js

Live Editor

Loading...

Output

Run code to see output...

Comments

Sign in to leave a comment. Your name and photo come from Google; nothing else is shared.

Loading comments...