Back to skills
extension
Category: OtherNo API key required

design-patterns

Use when architecting solutions, identifying recurring problems, or improving code structure with proven patterns.

personAuthor: piuaibot-stackhubclawhub

Design Patterns

Creational Patterns

  • Singleton — one instance globally (use sparingly, hard to test)
  • Factory Method — delegate instantiation to subclasses
  • Abstract Factory — families of related objects
  • Builder — step-by-step complex object construction
  • Prototype — clone existing objects

Structural Patterns

  • Adapter — incompatible interfaces compatibility
  • Decorator — add behavior without modifying class
  • Facade — simplified interface to complex subsystem
  • Proxy — control access to another object
  • Composite — tree structures, treat individual/group uniformly

Behavioral Patterns

  • Observer — event subscription/notification
  • Strategy — swap algorithms at runtime
  • Command — encapsulate actions as objects
  • Chain of Responsibility — pass request through handler chain
  • Template Method — define skeleton, let subclasses fill in
  • State — change behavior when internal state changes
  • Iterator — traverse collection without exposing internals

Modern Patterns

  • Repository — abstract data layer from business logic
  • Unit of Work — batch DB operations into a transaction
  • CQRS — separate read and write models
  • Saga — distributed transaction management
  • Circuit Breaker — prevent cascading failures

Anti-Patterns to Avoid

  • God Object — class that knows too much
  • Spaghetti Code — no clear structure
  • Golden Hammer — using one pattern for everything
  • Premature Optimization — optimizing before profiling