2

If I have multiple nodes that will need to modify a request, is it a good idea to still utilize the 'Chain of Responsibility' Design Pattern? Or should this pattern only be utilized when only one (unknown) node will exclusively handle the request?

IE: node 2 and node 3 will both need to affect the request (R). So even though node 2 handles the request, I still want to continue to pass the request down the list to the next handler

                    +--------+ (R)  +--------+ (R)  +--------+ (R)
Client Request (R)  | Node 1 |----->| Node 2 |----->| Node 3 |----->etc...
                    +--------+      +--------+      +--------+
veilig
  • 5,085
  • 10
  • 48
  • 86
  • Eh? What are you trying to do in **php** with this design? – Naftali Nov 12 '12 at 19:06
  • @Neal In a PHP site on a *nix system, I have to create a module that needs to verify permissions and user/group settings of a directory tree. So for each request in the tree I need to send it down through this chain where node 1 might validate if the request is a directory and check the correct perms are set, and node 2 might check if the request is a file and validate the perms. But then each request also needs to validate the user/group set for every request as well. But you're right - I prolly didn't need to tag this question as PHP (habit) – veilig Nov 12 '12 at 20:02

1 Answers1

0

From my point of view you would be better using a pipes and filters pattern, as each step adds some kind of transformation and/or validation.

This image is taken from the like above

enter image description here

At any point, one of the filters can decide to process the request and not pass it to the next filter. In the example above, (if it were an http request), an unauthenticated request would result in a 401 http status code.

Augusto
  • 28,839
  • 5
  • 58
  • 88