A curated, production-oriented collection of classic software design patterns implemented in Java.
Each pattern is expressed as small, focused, runnable code intended to demonstrate intent, structure, and trade-offs — not just theory.
This repository is designed as a long-term reference for backend engineers, architects, and senior developers.
- Provide clear, minimal implementations of well-known design patterns
- Emphasize when to use vs. when to avoid each pattern
- Encourage good architectural judgment, not pattern overuse
- Serve as a reference companion for real-world system design
- Backend engineers (Java / JVM ecosystem)
- Software architects and technical leads
- Developers preparing for system design interviews
- Anyone who wants practical pattern fluency, not just definitions
- Language: Java (21+)
- Build Tool: Maven
- Paradigm: Object-Oriented Design
- Testing: JUnit (where applicable)
- Java 21+
- Maven 3.8+
mvn clean testOpen the project as a Maven project using pom.xml in IntelliJ IDEA or Eclipse.
The repository is organized into five root modules to make it easier to navigate by intent:
| Category | Folder | What It Covers |
|---|---|---|
| GoF Patterns | gof-patterns/ |
Classic object-oriented patterns (creational/structural/behavioral) |
| Architectural Patterns | architectural-patterns/ |
System- and layer-level structuring patterns |
| Enterprise Integration Patterns | enterprise-integration-patterns/ |
Integration flows, pipelines, and message-oriented thinking |
| Reliability Patterns | reliability-patterns/ |
Concurrency/robustness patterns and failure-mode handling |
| Miscellaneous Patterns | miscellaneous-patterns/ |
Useful patterns that don’t fit cleanly elsewhere |
| Pattern | Folder | Typical Use Case |
|---|---|---|
| Abstract Factory | gof-patterns/abstract-factory/ |
Families of related objects |
| Adapter | gof-patterns/adapter/ |
Interface compatibility |
| Bridge | gof-patterns/bridge/ |
Decoupling abstraction & implementation |
| Builder | gof-patterns/builder/ |
Complex object construction |
| Chain of Responsibility | gof-patterns/chain/ |
Request pipelines |
| Command | gof-patterns/command/ |
Action encapsulation |
| Composite | gof-patterns/composite/ |
Tree structures |
| Decorator | gof-patterns/decorator/ |
Runtime behavior extension |
| Facade | gof-patterns/facade/ |
Simplified subsystem access |
| Factory Method | gof-patterns/factory-method/ |
Delegating object creation |
| Flyweight | gof-patterns/flyweight/ |
Memory optimization |
| Interpreter | gof-patterns/interpreter/ |
DSL-like grammars |
| Iterator | gof-patterns/iterator/ |
Collection traversal |
| Mediator | gof-patterns/mediator/ |
Interaction centralization |
| Memento | gof-patterns/memento/ |
State snapshots |
| Observer | gof-patterns/observer/ |
Event-driven updates |
| Prototype | gof-patterns/prototype/ |
Cloning costly objects |
| Proxy | gof-patterns/proxy/ |
Controlled access |
| Singleton | gof-patterns/singleton/ |
Controlled global access |
| State | gof-patterns/state/ |
State-driven behavior |
| Strategy | gof-patterns/strategy/ |
Algorithm selection |
| Template Method | gof-patterns/template-method/ |
Algorithm skeletons |
| Visitor | gof-patterns/visitor/ |
Operations on object graphs |
- Model-View-Presenter —
architectural-patterns/model-view-presenter/ - Service Locator —
architectural-patterns/service-locator/ - State Machine —
architectural-patterns/state-machine/
- Pipes & Filters —
enterprise-integration-patterns/pipes-and-filters/ - Saga —
enterprise-integration-patterns/saga/ - CQRS —
enterprise-integration-patterns/cqrs/ - Transactional Outbox —
enterprise-integration-patterns/transactional-outbox/
- Double-Checked Locking —
reliability-patterns/double-checked-locking/ - Circuit Breaker —
reliability-patterns/circuit-breaker/ - Null Object —
reliability-patterns/nullobject/ - Rate Limiter —
reliability-patterns/rate-limiter/ - Retry with Backoff —
reliability-patterns/retry-backoff/ - Bulkhead —
reliability-patterns/bulkhead/ - Hedge Requests —
reliability-patterns/hedge-requests/ - Timeout & Deadline Propagation —
reliability-patterns/timeout-deadline-propagation/ - Idempotency Keys —
reliability-patterns/idempotency-keys/
- Criteria / Filter —
miscellaneous-patterns/filter/ - Lazy Sequence —
miscellaneous-patterns/lazy-sequence/ - Method Object —
miscellaneous-patterns/method-object/ - Servant —
miscellaneous-patterns/servant/
For each pattern folder, focus on:
- Intent — what problem is being solved
- Roles — participants and responsibilities
- Trade-offs — costs vs. benefits
- Alternatives — simpler options to consider
Patterns are tools, not goals. Overuse is a design smell.
- Patterns that demonstrate behavior include unit tests
- Tests focus on observable behavior, not implementation details
- Examples remain intentionally small and readable
- SOLID principles
- Composition over inheritance
- Separation of concerns
- Dependency inversion
- Explicit design trade-offs
- More patterns
- Better formatted PDF Book
- Better formatted github-pages
- Visible Diagrams in PDF Book
Contributions are welcome and encouraged!
- Improved examples with clearer intent
- Additional tests that demonstrate behavior
- Documentation clarifications
- New patterns with justification
see CONTRIBUTING.md for details.
This project is licensed under the MIT License — free to use, modify, and distribute.