🎨 Design Patterns (Gang of Four)
Beginner
What is the Chain of Responsibility design pattern?
Answer
The Chain of Responsibility pattern passes a request along a chain of handlers. Each handler decides either to process the request or to pass it to the next handler in the chain. This decouples the sender of a request from its receivers. A practical example is HTTP middleware in web frameworks — a request passes through authentication middleware, then logging middleware, then rate-limiting middleware before reaching the controller. Another example is a customer support system where a request escalates from a chatbot to a tier-1 agent to a specialist. The pattern allows you to assemble chains dynamically at runtime.