Behavioral

Chain of Responsibility

Description

Lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.

Where to use

  • Request processing pipelines.
  • \n
  • UI event bubbling.
  • \n
  • Middleware.

Real World Example

Web Server Middleware: Authentication -> Logging -> Compression -> Router. Each step passes control to the next.

Code Example

class ChainofResponsibility:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Chain of Responsibility')