Chain of Responsibility
Suppose we have a group of objects that together are meant to solve a problem. When one object can't solve a problem, we want the object to send the task to a different object in a given chain. This is what the Chain of Responsibility design pattern is used for.
In order to get this to work, we need a handler, which will be our Chain
interface. The various objects in the chain will all implement this Chain
interface.
Let's start with a simple example; an associate can purchase an asset for less than $100, a manager can purchase something for less than $500.
Our abstraction for the Purchaser
interface looks like this:
<?php interface Purchaser { public function setNextPurchaser(Purchaser $nextPurchaser): bool; public function ...
Get Mastering PHP Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.