Chain of Responsibility: split merged handlers, add missing Level3/Critical classes, Java 25, H6 labels, README mapping
This commit is contained in:
31
03-behavioral/chain-of-responsibility/README.md
Normal file
31
03-behavioral/chain-of-responsibility/README.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Chain of Responsibility Design Pattern — Java Example
|
||||||
|
|
||||||
|
**Pattern:** Behavioral → Chain of Responsibility
|
||||||
|
**Article:** https://ankurm.com/chain-of-responsibility-design-pattern-java/
|
||||||
|
|
||||||
|
## What this example shows
|
||||||
|
|
||||||
|
A support-ticket routing system: four handlers (`Level1Support`, `Level2Support`, `Level3Support`, `CriticalIncidentTeam`) are chained together via `SupportHandler.setNext()`. Each handler checks `canHandle()` for the ticket's priority — if it can't handle the ticket, it logs that it's passing the ticket up and delegates to the next handler in the chain. The sender (`Main`) only ever talks to the first handler; it has no idea which handler will ultimately resolve each ticket.
|
||||||
|
|
||||||
|
## How to run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
javac chain-of-responsibility/*.java -d out/chain
|
||||||
|
java -cp out/chain chain.Main
|
||||||
|
```
|
||||||
|
|
||||||
|
Requires Java 25.
|
||||||
|
|
||||||
|
## Post Section ↔ File Mapping
|
||||||
|
|
||||||
|
| Post Section | File(s) |
|
||||||
|
|---|---|
|
||||||
|
| The Problem: Rigid Routing Logic | illustrative only — not part of this repository's runnable example |
|
||||||
|
| Implementation: Support Ticket Escalation — base handler | `SupportHandler.java` |
|
||||||
|
| Implementation: Support Ticket Escalation — the ticket | `SupportTicket.java` |
|
||||||
|
| Each concrete handler checks only its own responsibility — Level 1 & 2 | `Level1Support.java`, `Level2Support.java` |
|
||||||
|
| Level3Support and CriticalIncidentTeam follow exactly the same shape | `Level3Support.java`, `CriticalIncidentTeam.java` |
|
||||||
|
| The chain is assembled in one place | `Main.java` |
|
||||||
|
|
||||||
|
Article: https://ankurm.com/chain-of-responsibility-design-pattern-java/
|
||||||
|
All patterns: https://ankurm.com/design-patterns-java/
|
||||||
17
README.md
17
README.md
@@ -305,6 +305,23 @@ javac 02-structural/proxy/*.java -d out/proxy
|
|||||||
java -cp out/proxy proxy.Main
|
java -cp out/proxy proxy.Main
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Chain of Responsibility (`03-behavioral/chain-of-responsibility/`)
|
||||||
|
|
||||||
|
| Post Section | File(s) |
|
||||||
|
|---|---|
|
||||||
|
| The Problem: Rigid Routing Logic | illustrative only — not part of this repository's runnable example |
|
||||||
|
| Implementation: Support Ticket Escalation — base handler | `SupportHandler.java` |
|
||||||
|
| Implementation: Support Ticket Escalation — the ticket | `SupportTicket.java` |
|
||||||
|
| Each concrete handler checks only its own responsibility — Level 1 & 2 | `Level1Support.java`, `Level2Support.java` |
|
||||||
|
| Level3Support and CriticalIncidentTeam follow exactly the same shape | `Level3Support.java`, `CriticalIncidentTeam.java` |
|
||||||
|
| The chain is assembled in one place | `Main.java` |
|
||||||
|
|
||||||
|
Run it:
|
||||||
|
```bash
|
||||||
|
javac 03-behavioral/chain-of-responsibility/*.java -d out/chain
|
||||||
|
java -cp out/chain chain.Main
|
||||||
|
```
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
- *Design Patterns: Elements of Reusable Object-Oriented Software* — Gamma, Helm, Johnson, Vlissides
|
- *Design Patterns: Elements of Reusable Object-Oriented Software* — Gamma, Helm, Johnson, Vlissides
|
||||||
|
|||||||
Reference in New Issue
Block a user