Ankit Zalani
Ankit Zalani

Reputation: 3168

What is the difference between chain of responsibility and filter pattern

Chain of responsibility seems to be very similar to filter pattern. I would like to know:

If they are different then what are the problem domains where one is applicable and the other one is not.

Upvotes: 5

Views: 2054

Answers (1)

Jakub Filipczyk
Jakub Filipczyk

Reputation: 1141

I think the main difference is that in filter pattern all filters in the chain will be executed in given order. Chain of responsibility is more elastic - every chain element decides about two things:

  1. if it should handle the request
  2. if it should pass the request to the next chain element

The main concept in Chain of responsibility is that you move the steering logic into chain elements. The calling code does not have to make a decision (by some complex IF statements) which logic should be called but the "logic" (extracted to an element of chain) itself knows if it should handle request.

In my opinion Filter Pattern is a simplified variant of Chain of responsibility.

Upvotes: 11

Related Questions