90 lines
3.4 KiB
Markdown
90 lines
3.4 KiB
Markdown
# 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
|
|
|
|
```bash
|
|
# Linux / macOS / Git Bash (Windows)
|
|
javac 03-behavioral/strategy/*.java -d out/strategy
|
|
java -cp out/strategy strategy.Main
|
|
```
|
|
|
|
```cmd
|
|
REM Windows Command Prompt
|
|
javac 03-behavioral\strategy\*.java -d out\strategy
|
|
java -cp out\strategy strategy.Main
|
|
```
|
|
|
|
## 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
|