June 2017
Intermediate to advanced
536 pages
9h 49m
English
The chain of responsibility pattern allows us to chain code in a sender-receiver manner, while the two are decoupled from each other. This makes it possible to have more than one object handle incoming requests.
The following example demonstrates a possible chain of responsibility pattern implementation using the logger functionality as an example:
<?phpabstract class Logger{ private $logNext = null; public function logNext(Logger $logger) { $this->logNext = $logger; return $this->logNext; } final public function push($message) { $this->log($message); if ($this->logNext !== null) { $this->logNext->push($message); } } abstract protected function log($message);}class SystemLogger extends Logger{ public function ...
Read now
Unlock full access