Pattern Cheat Sheet
All 37 patterns on one page. Keep this open during architecture reviews, system design interviews, or code review sessions.
PatternSimple — Design Pattern Cheat Sheet
All 37 patterns · patternsimple.dev
Creational — How objects are created
5 patternsEnsure a class has only one instance, and provide a global point of access to it.
→You need exactly one shared resource — like a logger, config manager, or connection pool.
→The object is expensive to create and you want to reuse it across the application.
Define an interface for creating objects, but let subclasses decide which class to instantiate.
→You don't know at compile time which class you need to instantiate.
→You want to centralise and control object creation logic in one place.
Create families of related objects without specifying concrete classes
→You need to create families of related objects that must be used together
→Your system needs to be independent of how its products are created
Separate construction from representation
→Creating objects with many optional parameters or configurations
→Building complex objects with a multi-step construction process
Create objects by cloning an existing prototype
→Object creation is expensive (database queries, API calls, heavy computation)
→You need multiple similar objects with slight variations
Structural — How objects are composed
7 patternsConvert incompatible interfaces into compatible ones
→Integrating with third-party libraries that have incompatible interfaces
→Working with legacy code that you cannot or should not modify
Decouple abstraction from implementation so they can vary independently
→Separating abstraction from implementation when both should be extensible independently
→Avoiding permanent binding between abstraction and implementation
Compose objects into tree structures to represent hierarchies
→Building hierarchical tree structures (file systems, organizational charts, UI components)
→When you need to treat individual objects and groups of objects identically
Add responsibilities to objects dynamically
→Adding features to objects without modifying their original class
→Creating flexible combinations of behaviors (coffee with milk, sugar, and chocolate)
Provide a simplified interface to a complex subsystem of classes.
→A subsystem is complex and most callers only need a simple subset of its functionality.
→You want to layer your architecture — expose a clean API while hiding implementation details.
Share fine-grained objects efficiently to reduce memory usage
→Creating many similar objects where memory is a concern
→Objects have much shareable (intrinsic) state vs. unique (extrinsic) state
Control access to another object through a surrogate
→Lazy loading: delay expensive object creation until actually needed
→Access control: restrict who can use an object or what they can do
Behavioral — How objects communicate
10 patternsPass a request along a chain of handlers. Each handler decides either to process the request or pass it along the chain
→Multiple objects can handle a request and the handler isn't known in advance
→Request handlers should be determined dynamically at runtime
Encapsulate a request as an object, allowing you to parameterize clients with different requests, queue them, and log them
→You need to queue requests and execute them later
→Implementing undo/redo functionality
Provide a way to access the elements of an object sequentially without exposing its underlying representation
→You need to access collection elements without exposing the internal structure
→You want to support multiple simultaneous traversals of the same collection
Define an object that encapsulates how a set of objects interact
→Objects have many interdependencies creating complex communication
→You want to decouple objects from directly knowing each other
Capture and externalize an object's internal state without violating encapsulation, allowing it to be restored later
→You need undo/redo functionality
→You want to save and restore object state
Define a one-to-many dependency where when one object changes state, all its dependents are notified automatically
→You need to notify multiple objects when state changes occur
→Objects interested in updates don't know each other in advance
Allow an object to alter its behavior when its internal state changes
→Object behavior depends on state and changes at runtime
→You have many conditional statements (if/else or switch) based on state
Define a family of algorithms, encapsulate each one, and make them interchangeable
→You have multiple ways to solve a problem and need to select at runtime
→You want to avoid conditional statements (if/else or switch) scattered throughout code
Define the skeleton of an algorithm in a base class, deferring some steps to subclasses
→Multiple classes implement similar algorithms with slight variations
→You want to avoid code duplication of common algorithm structure
Represent an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates
→You have a complex object structure with many different element types
→You need many different, unrelated operations on the structure
AI Agent & LLM Patterns
8 patternsGround LLM responses in real data by retrieving relevant documents before generating an answer.
→You need up-to-date information beyond the LLM's training data
→Domain-specific or proprietary knowledge is critical
Break down complex problems into step-by-step reasoning to improve answer quality.
→Problems require multi-step reasoning or mathematical calculations
→Questions involve logic, planning, or causal reasoning
Combine reasoning and action: think through steps and execute tools to solve tasks.
→Tasks require gathering information from external sources
→Actions must be taken based on intermediate reasoning
Enable LLMs to call functions and external tools to expand their capabilities.
→Tasks require real-time data or calculations
→You need to integrate with external APIs or databases
Coordinate multiple specialized agents working together to solve complex problems.
→Tasks require diverse expertise (research, coding, design, review)
→Different subtasks would benefit from specialized agents
Generate, critique, and refine outputs iteratively to improve quality.
→Quality is more important than speed (creative writing, analysis)
→Complex tasks benefit from revision (code generation, essays)
Maintain context across interactions using short-term and long-term memory systems.
→Multi-turn conversations longer than context window
→Agents need to learn from interactions across sessions
Validate inputs and outputs to ensure safety, quality, and compliance.
→Safety and content moderation are critical
→Regulatory compliance is required (HIPAA, GDPR)
ML System & MLOps Patterns
7 patternsCentralize feature computation, storage, and serving so training and inference always use the exact same data.
→Multiple models sharing overlapping feature sets
→Strict SLA on serving latency (need pre-computed online features)
A versioned catalog of trained ML models with metadata, lineage, and stage transitions from staging to production.
→Multiple models in production (need to track which is deployed)
→Regulatory compliance requires audit trail of model decisions
Automated, reproducible workflows that ingest data, train models, evaluate them, and register successful runs.
→Regular retraining needed (daily/weekly as new data arrives)
→Multiple models being trained independently (consolidate into one pipeline)
Deploy ML models behind a scalable, low-latency API that handles feature lookup, prediction, and response transformation.
→Real-time predictions needed (< 100ms SLA)
→High QPS (queries per second) requiring horizontal scaling
Track datasets like code with immutable versions so any model run can be reproduced months later.
→Models require reproducibility (audit trail, regulatory compliance)
→Frequently retraining with new data versions
Continuously track model performance, input distributions, and prediction drift to catch silent failures in production.
→Models in production serving real users
→Need to detect silent failures (accuracy degradation without labels)
Safely roll out new models by routing a fraction of traffic to the candidate and comparing business metrics against the control.
→Deploying a new model to production with business impact
→Want to prove statistical significance before promoting