Skip to content
Commitwise
Menu

Chain of Responsibility pattern

Also called: Middleware, Interceptor chain

A request passes along a chain of handlers until one handles it, or through every handler as middleware.

Definition

In the routing form, each handler handles the request or passes it on; specific handlers come before general ones and a fallback ends the chain. In the middleware form (servlet filters, OkHttp interceptors, Express middleware), every handler can act before and after calling next, must call it exactly once unless it deliberately stops or retries, and the order of handlers decides what each one sees.

In practice

Deep links go through order, sale, product and promo handlers, and fall back to the home screen.

Related terms

Esc

Type to search the whole site.