Chain of Responsibility Pattern

From NovaOrdis Knowledge Base
Revision as of 20:48, 8 January 2018 by Ovidiu (talk | contribs) (→‎Overview)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview

The Chain of Responsibility is a behavioral pattern that prevents coupling the sender of a request to its receiver(s). It also gives more than one receiver the change to handle the request. The receivers are organized in a chain where, at a certain point in the chain, the request is either handled or passed to the next link in the chain. The first object in the chain receives the request and either handles it or forwards it to the next candidate on the chain, which does likewise. The object that ultimately handles the request isn't known to the object that initiates the request, and we say that the request has an implicit receiver.

In order to provide the chain or responsibility functionality, each object in the chain must implement two interfaces:

  • an interface for handling the request
  • an interface for accessing the successor in the chain