Chain of Responsibility

Route requests through a chain of handlers with fallback behavior.

65|15|Updated Mar 8, 2026
One-click install
npx skills add https://github.com/microwind/ai-skills --skill chain-of-responsibility
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Chain of Responsibility
Source: https://github.com/microwind/ai-skills/tree/main/design-patterns/chain-of-responsibility-pattern
Command: npx skills add https://github.com/microwind/ai-skills --skill chain-of-responsibility

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

将请求沿着一组处理者逐一传递,解耦请求发起者与具体处理者,避免硬编码的直接调用,从而提升系统的可扩展性与维护性。

Core Features & Use Cases

  • 解耦与灵活性:请求发送者与处理链解耦,便于动态新增、移除或重新排序处理者。
  • 可扩展的处理链:可以在不修改发起端的情况下增添新的 ConcreteHandler 实现。
  • 默认与回退处理:链中可以设定默认处理或回退逻辑,确保请求不丢失。
  • 常见用例包括日志路由、身份验证与授权、输入校验,以及按步骤执行的工作流。

Quick Start

构建一个处理链,将请求从头节点逐个传递给后续处理者,直到被某个处理者处理。

Frequently Asked Questions about Chain of Responsibility

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I decouple request senders from specific handlers in a multi-step workflow?▼

To decouple request senders from specific handlers, route requests through a chain of responsibility where each processor decides to handle the request or pass it to a successor. This avoids hardcoding direct calls and enables dynamic insertion or removal of handlers.

What is the best way to implement a flexible authentication and validation pipeline?▼

The best way to implement a flexible authentication and validation pipeline is using a chain of responsibility. You can link multiple concrete handlers sequentially, allowing each to validate or authenticate the request before passing it along the chain.

How does a handler chain manage requests that no processor can handle?▼

A handler chain manages unhandled requests by providing clear termination or fallback behavior. The chain of responsibility can be configured with a default handler at the end to ensure requests are not lost if no concrete handler processes them.

Can I dynamically add or reorder handlers in a request chain without modifying the sender?▼

Yes, you can dynamically add, remove, or reorder handlers in a request chain without modifying the sender. The chain of responsibility pattern decouples the request initiator from the processing logic, ensuring high extensibility for new ConcreteHandler implementations.

When should I use a chain of responsibility pattern instead of direct function calls?▼

You should use a chain of responsibility pattern instead of direct function calls when you need to process requests through multiple potential handlers like logging, authorization, or validation workflows. It prevents tight coupling and allows flexible routing.

Does the chain of responsibility pattern support middleware for logging and authorization?▼

Yes, the chain of responsibility pattern effectively supports middleware for logging and authorization. It routes requests through a linked list of processors, allowing distinct handlers to manage logging and authorization steps sequentially before final execution.