39 lines
1.4 KiB
Java
39 lines
1.4 KiB
Java
package chain;
|
|
|
|
/**
|
|
* Chain of Responsibility Design Pattern — Runnable Demo
|
|
*
|
|
* A support ticket routing system where each handler
|
|
* either resolves a ticket or passes it up the chain.
|
|
*
|
|
* Run: javac chain/*.java -d out/chain && java -cp out/chain chain.Main
|
|
* Article: https://ankurm.com/chain-of-responsibility-design-pattern-java/
|
|
*/
|
|
public class Main {
|
|
|
|
public static void main(String[] args) {
|
|
System.out.println("=== Chain of Responsibility Demo ===\n");
|
|
|
|
// Build the chain: L1 -> L2 -> L3 -> Critical
|
|
SupportHandler l1 = new Level1Support();
|
|
l1.setNext(new Level2Support())
|
|
.setNext(new Level3Support())
|
|
.setNext(new CriticalIncidentTeam());
|
|
|
|
SupportTicket[] tickets = {
|
|
new SupportTicket("Can't find the login button", SupportTicket.Priority.LOW),
|
|
new SupportTicket("API returns 500 on /checkout", SupportTicket.Priority.MEDIUM),
|
|
new SupportTicket("Database replication lag > 30s", SupportTicket.Priority.HIGH),
|
|
new SupportTicket("Complete payment system outage", SupportTicket.Priority.CRITICAL),
|
|
};
|
|
|
|
for (SupportTicket t : tickets) {
|
|
System.out.println("Ticket: " + t);
|
|
l1.handleRequest(t);
|
|
System.out.println();
|
|
}
|
|
|
|
System.out.println("=== Demo complete ===");
|
|
}
|
|
}
|