DELAPARRA
Index
Color
NL
Category: Design patterns

Chain of Responsibility

Explained by Updated

What is Chain of Responsibility?

Chain of Responsibility: Pass a request along a chain of handlers, each deciding to process it or pass it to the next handler in the chain. In the Chain of Responsibility pattern, a request passes through a series of handlers. Each handler either deals with it or passes it on to the next one.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Chain of Responsibility

How is Chain of Responsibility used in practice?

HTTP middleware is the best-known example. A request passes through authentication, rate limiting, locale detection and so on. Any handler can stop the chain, for example by returning a 401, or let the request continue to the controller.

What should you keep in mind with Chain of Responsibility?

The pattern keeps each step small and independent, and you can add or reorder steps without touching the others. The risk is that the order matters and is easy to get wrong. If logging runs before authentication, you log requests you later reject. Keep the chain short enough that someone can read it top to bottom, and document why the order is what it is.

At a glance

CategoryDesign patterns
Explained by
Updated

More Design patterns terms

All terms starting with C

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.