The Chain of Responsibility pattern is implemented by defining a handler abstraction with a process method and a reference to the next handler, then linking concrete handler instances together so a request travels along the chain until one of them handles it.
A logging framework might chain a ConsoleLogger, FileLogger, and EmailLogger, where each handler decides based on severity whether to log the message and whether to also pass it to the next logger in the chain.
abstract class Handler {
protected Handler next;
Handler setNext(Handler next) {
this.next = next;
return next;
}
abstract void handle(Request request);
}
class ManagerHandler extends Handler {
void handle(Request request) {
if (request.getAmount() <= 1000) {
System.out.println("Approved by manager");
} else if (next != null) {
next.handle(request);
}
}
}A concise interview answer is
I define a Handler abstraction with a handle() method and a link to the next handler, implement each concrete handler to process or forward the request, then chain instances together at setup time. The client only needs the head of the chain, which keeps handler logic decoupled from routing logic.
Last updated: 16 July 2026
Previous question: What is the Chain of Responsibility pattern and how does it work?
Next question: Can you provide an example of when you would use the Chain of Responsibility pattern?