The responsibility chain pattern is a behavioral pattern, which contains some command objects and a series of processing objects. Each processing object determines which command objects it can handle, and it knows how to pass a Command object that it cannot handle to the next processing object in the chain. The pattern also describes how to add a new processing object to the end of the processing chain.
Main role
Abstract responsibility (Responsibility) Role: Defines public methods that are supported by all responsibilities.
Specific responsibilities (concrete Responsibility) Role: specific responsibilities implemented with abstract responsibility interfaces
Responsibility chain (Chain of responsibility) role: Set call rules for responsibility
Class diagram
Instance
<?phpabstract class Responsibility {//abstract responsibility role protected $next;//Next Responsibility Role public function Setnext ( Responsibility $l) { $this->next = $l; return $this; } Abstract public function operate (); Action method} class Responsibilitya extends Responsibility {public function __construct () {} public function operate ( { if (false = = Is_null ($this->next)) { $this->next->operate (); } };} Class Responsibilityb extends Responsibility {public function __construct () {} public function operate () { C14/>if (False = = Is_null ($this->next)) { $this->next->operate (); } };} $res _a = new Responsibilitya (); $res _b = new Responsibilityb (); $res _a->setnext ($res _b);? >