2

I'm trying to get my head around these two patterns and am wondering about the similarities and differences. To me they are similiar in ways as they both seem to use the step by step process. Could someone shed some more light on these two patterns? Am I right in saying that the pipe and filter pattern would be used in larger scale applications and builder pattern used on small scale applications? Sorry to go on a bit but in builder pattern do all steps happen at the same time i.e. all attributes passed to the builder before the completed object is returned?

Thanks.

Sattar Imamov
  • 534
  • 6
  • 16
SamL
  • 123
  • 1
  • 2
  • 11

1 Answers1

2

Pipes and Filters pattern is Enterprice integration pattern, while the Builder pattern is one of the object-oriented design pattern.

These two patterns have a different semantics:

  • Pipes and Filters used for perform complex processing on a messages that come from heterogeneous systems. Through Pipes message is transmitted to the Filters. Filters, in turn, processes the received message, and transmits the next Pipes.
  • Builder pattern is a object ceation design pattern. It is used when the process of creating a set of objects consist of several steps.

As you can see, it is incorrect to compare these two patterns. But they can be used in conjunction: using Builder you can configure what will Filters participate in the processing of the message type of T. After, configured object can be used:

  • To create Endpoints (it will Pipes), through which the message will be transmitted

  • To create a Processes (or even instances of virtual machines, it depends on the application) that will process messages (this will Filters)

For example, you have Book sale system:

  • Buyers are divided into two types: ordinary and privileged.
  • Privileged users receive a discount N percent.

In this case Pipes may be a TCP channel, Filters will process the order.

The ordering process for ordinary users would be:

  1. Adding books to basket
  2. Authorization
  3. Withdrawal of money from the card

The ordering process for privileged users:

  1. Adding books to basket
  2. Authorization
  3. Calculation of discounts
  4. Withdrawal of money from the card

As can be seen, the two processes differ from each other by one step. Branching process occurs after the user's authorization. After user authorization, Filter #2 (Authorization) must generate and send a message of a certain type: privileged or normal user. After sending this message should react different Filters. Filter for discount calculation for the privileged user or withdrawal of money for the ordinary user. This configuration in declarative manner can be describe using Builder pattern.

Sattar Imamov
  • 534
  • 6
  • 16
  • Hi Sattar, thats a super answer. Thanks very much for clearing that up for me. Regards. – SamL Apr 11 '15 at 19:35