Add all 23 GoF design pattern implementations (2026-06-13)
This commit is contained in:
98
README.md
Normal file
98
README.md
Normal file
@@ -0,0 +1,98 @@
|
||||
# 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](https://ankurm.com/gof-design-patterns-java/) 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
|
||||
|
||||
```powershell
|
||||
# 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
|
||||
```
|
||||
|
||||
```bash
|
||||
# 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
|
||||
powershell -ExecutionPolicy Bypass -File run-behavioral.ps1
|
||||
```
|
||||
|
||||
## Articles
|
||||
|
||||
| Pattern | Category | Article |
|
||||
|---------|----------|---------|
|
||||
| Factory Method | Creational | https://ankurm.com/factory-method-design-pattern-java/ |
|
||||
| Abstract Factory | Creational | https://ankurm.com/abstract-factory-design-pattern-java/ |
|
||||
| Builder | Creational | https://ankurm.com/builder-design-pattern-java/ |
|
||||
| Prototype | Creational | https://ankurm.com/prototype-design-pattern-java/ |
|
||||
| Singleton | Creational | https://ankurm.com/singleton-design-pattern-java/ |
|
||||
| Adapter | Structural | https://ankurm.com/adapter-design-pattern-java/ |
|
||||
| Bridge | Structural | https://ankurm.com/bridge-design-pattern-java/ |
|
||||
| Composite | Structural | https://ankurm.com/composite-design-pattern-java/ |
|
||||
| Decorator | Structural | https://ankurm.com/decorator-design-pattern-java/ |
|
||||
| Facade | Structural | https://ankurm.com/facade-design-pattern-java/ |
|
||||
| Flyweight | Structural | https://ankurm.com/flyweight-design-pattern-java/ |
|
||||
| Proxy | Structural | https://ankurm.com/proxy-design-pattern-java/ |
|
||||
| Chain of Responsibility | Behavioral | https://ankurm.com/chain-of-responsibility-design-pattern-java/ |
|
||||
| Command | Behavioral | https://ankurm.com/command-design-pattern-java/ |
|
||||
| Interpreter | Behavioral | https://ankurm.com/interpreter-design-pattern-java/ |
|
||||
| Iterator | Behavioral | https://ankurm.com/iterator-design-pattern-java/ |
|
||||
| Mediator | Behavioral | https://ankurm.com/mediator-design-pattern-java/ |
|
||||
| Memento | Behavioral | https://ankurm.com/memento-design-pattern-java/ |
|
||||
| Observer | Behavioral | https://ankurm.com/observer-design-pattern-java/ |
|
||||
| State | Behavioral | https://ankurm.com/state-design-pattern-java/ |
|
||||
| Strategy | Behavioral | https://ankurm.com/strategy-design-pattern-java/ |
|
||||
| Template Method | Behavioral | https://ankurm.com/template-method-design-pattern-java/ |
|
||||
| Visitor | Behavioral | https://ankurm.com/visitor-design-pattern-java/ |
|
||||
|
||||
## Reference
|
||||
|
||||
- *Design Patterns: Elements of Reusable Object-Oriented Software* — Gamma, Helm, Johnson, Vlissides
|
||||
- https://refactoring.guru/design-patterns
|
||||
Reference in New Issue
Block a user