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.
| Pattern | Folder | Typical Use Case |
|---|---|---|
| Abstract Factory | abstract-factory/ |
Families of related objects |
| Builder | builder/ |
Complex object construction |
| Factory Method | factory-method/ |
Delegating object creation |
| Prototype | prototype/ |
Cloning costly objects |
| Singleton | singleton/ |
Controlled global access |
| Pattern | Folder | Typical Use Case |
|---|---|---|
| Adapter | adapter/ |
Interface compatibility |
| Bridge | bridge/ |
Decoupling abstraction & impl |
| Composite | composite/ |
Tree structures |
| Decorator | decorator/ |
Runtime behavior extension |
| Facade | facade/ |
Simplified subsystem access |
| Flyweight | flyweight/ |
Memory optimization |
| Proxy | proxy/ |
Controlled access |
| Pattern | Folder | Typical Use Case |
|---|---|---|
| Chain of Responsibility | chain/ |
Request pipelines |
| Command | command/ |
Action encapsulation |
| Interpreter | interpreter/ |
DSL-like grammars |
| Iterator | iterator/ |
Collection traversal |
| Mediator | mediator/ |
Interaction centralization |
| Memento | memento/ |
State snapshots |
| Observer | observer/ |
Event-driven updates |
| State | state/ |
Workflow/state machines |
| Strategy | strategy/ |
Algorithm selection |
| Template Method | template-method/ |
Algorithm skeletons |
| Visitor | visitor/ |
Operations on object graphs |
| MVP | model-view-presenter/ |
Presentation separation |
- Finite State Machine —
state-machine/ - Pipes & Filters —
pipes-and-filters/ - Service Locator —
service-locator/ - Double-Checked Locking —
double-checked-locking/ - Method Object —
method-object/
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
- Add a short README.md inside each pattern folder
- Add UML-style diagrams (Mermaid) per pattern
- Add pattern comparison guide (e.g. Strategy vs State vs Command)
- Enforce formatting & static analysis
- Publish tagged releases (v1.x)
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.