3.7 KiB
3.7 KiB
GoF Design Patterns in Java
Complete runnable Java 17 implementations of all 23 Gang of Four design patterns. Each pattern has a dedicated article at ankurm.com with a UML diagram, step-by-step explanation, and console output.
Structure
design-patterns/
├── 01-creational/
│ ├── factory-method/
│ ├── abstract-factory/
│ ├── builder/
│ ├── prototype/
│ └── singleton/
├── 02-structural/
│ ├── adapter/
│ ├── bridge/
│ ├── composite/
│ ├── decorator/
│ ├── facade/
│ ├── flyweight/
│ └── proxy/
└── 03-behavioral/
├── chain-of-responsibility/
├── command/
├── interpreter/
├── iterator/
├── mediator/
├── memento/
├── observer/
├── state/
├── strategy/
├── template-method/
└── visitor/
Prerequisites
- Java 17+ (Eclipse Temurin recommended)
- No build tool required — plain
javac/java
Run any pattern
# Windows (PowerShell)
$JAVAC = 'C:\Program Files\Eclipse Adoptium\jdk-17.0.7.7-hotspot\bin\javac.exe'
$JAVA = 'C:\Program Files\Eclipse Adoptium\jdk-17.0.7.7-hotspot\bin\java.exe'
& $JAVAC 03-behavioral/strategy/*.java -d out/strategy
& $JAVA -cp out/strategy strategy.Main
# Linux / macOS
javac 03-behavioral/strategy/*.java -d out/strategy
java -cp out/strategy strategy.Main
Run all behavioral patterns (Windows)
Double-click RUN-behavioral.bat or run in PowerShell:
powershell -ExecutionPolicy Bypass -File run-behavioral.ps1
Articles
Reference
- Design Patterns: Elements of Reusable Object-Oriented Software — Gamma, Helm, Johnson, Vlissides
- https://refactoring.guru/design-patterns