Behavioral Patterns

notifications_active

Event-Driven Patterns

Observer Pattern

One-to-many dependency where observers automatically receive notifications when subject state changes, enabling pub/sub and reactive systems.

Key Features
  • Loose coupling between subject and observers
  • Event handling and propagation
  • Reactive system foundation
  • GUI framework backbone
Use Cases
  • Event listeners (DOM events)
  • Reactive streams (RxJS, React)
  • MVC model updates
  • Publish-subscribe systems
Mediator Pattern

Centralized communication hub that reduces coupling between objects by coordinating their interactions through a single mediator.

Key Features
  • Simplifies complex object protocols
  • Centralizes communication control
  • Makes dependencies explicit
  • Reduces many-to-many to one-to-many
Use Cases
  • Chat room coordination
  • Air traffic control systems
  • UI form validation
  • Event bus implementations
Chain of Responsibility

Request handling chain where each handler decides to process the request or pass it to the next handler in sequence.

Key Features
  • Decouples senders from receivers
  • Flexible handler assignment
  • Sequential processing pipeline
  • Dynamic chain composition
Use Cases
  • Middleware pipelines (Express)
  • Logging level handlers
  • Event propagation (bubbling)
  • Approval workflow systems
Event Sourcing

Stores state changes as sequence of events rather than current state, enabling full audit trail and time travel debugging.

Key Features
  • Complete audit history
  • Event replay capability
  • Temporal queries support
  • Event-driven architecture foundation
Use Cases
  • Financial transaction systems
  • Version control systems
  • Audit logging requirements
  • CQRS implementations
swap_horiz

State & Strategy Patterns

State Pattern

Object behavior changes based on internal state, with state-specific behavior encapsulated in separate state classes.

Key Features
  • State-specific behavior encapsulation
  • Eliminates conditional statements
  • Explicit state transition logic
  • State classes for clarity
Use Cases
  • TCP connection states
  • Vending machine logic
  • Workflow engine states
  • Game character states
Strategy Pattern

Defines interchangeable algorithm family with runtime algorithm selection, favoring composition over inheritance.

Key Features
  • Algorithm family encapsulation
  • Composition over inheritance
  • Open/closed principle adherence
  • Runtime algorithm swapping
Use Cases
  • Sorting algorithms selection
  • Compression strategies
  • Payment method selection
  • Route planning algorithms
Template Method

Defines algorithm skeleton in base class with subclasses overriding specific steps, following Hollywood Principle.

Key Features
  • Code reuse through inheritance
  • Hooks for customization
  • Hollywood principle (don't call us)
  • Invariant parts in superclass
Use Cases
  • Framework lifecycle hooks
  • Data processing pipelines
  • UI component rendering
  • Parser implementations
settings_input_component

Command & Behavioral Patterns

Command Pattern

Encapsulates requests as objects, enabling parameterization, queueing, logging, and undo/redo operations.

Key Features
  • Undo/redo functionality
  • Macro command composition
  • Transactional behavior support
  • Delayed execution capability
Use Cases
  • UI action handlers
  • Job queue systems
  • Transaction management
  • Database migration tools
Iterator Pattern

Provides sequential access to collection elements without exposing underlying structure, supporting multiple traversals.

Key Features
  • Uniform traversal interface
  • Multiple concurrent iterations
  • Lazy evaluation support
  • Internal structure hiding
Use Cases
  • For-each loops (language built-in)
  • Database cursors
  • Stream APIs (Java, Node)
  • Pagination implementations
Visitor Pattern

Separates algorithms from object structure through double dispatch, enabling new operations without changing element classes.

Key Features
  • New operations without class changes
  • Double dispatch mechanism
  • Type safety preservation
  • Operation consolidation
Use Cases
  • Compiler AST traversal
  • Export to different formats
  • Tax calculation systems
  • Validation frameworks