This repository is a curated set of Java examples for common software design patterns.
- Java 17+
src/main/java/
├── singleton/ # Creational
├── factorymethod/
├── abstractfactory/
├── prototype/
├── builder/
├── adapter/ # Structural
├── decorator/
├── composite/
├── facade/
├── proxy/
├── strategy/ # Behavioral
├── observer/
├── command/
├── templatemethod/
├── state/
└── chain/ # Chain of Responsibility
Each pattern package contains:
Example.java: a runnable example with amainmethod.README.md: explains the problem, how the pattern works, key roles, and example flow.
Smoke tests live in src/test/java/.
- Singleton (
singleton) - Factory Method (
factorymethod) - Abstract Factory (
abstractfactory) - Prototype (
prototype) - Builder (
builder)
- Adapter (
adapter) - Decorator (
decorator) - Composite (
composite) - Facade (
facade) - Proxy (
proxy)
- Strategy (
strategy) - Observer (
observer) - Command (
command) - Template Method (
templatemethod) - State (
state) - Chain of Responsibility (
chain)
./gradlew build./gradlew runExample -Ppattern=strategyAvailable values for -Ppattern: singleton, factorymethod, abstractfactory, prototype, builder, adapter, decorator, composite, facade, proxy, strategy, observer, command, templatemethod, state, chain.
./gradlew runAll./gradlew test