LearningTech

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:
    def __init__(self):
        pass

    def execute(self):
        print('Executing Chain of Responsibility')