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:
- Adding books to basket
- Authorization
- Withdrawal of money from the card
The ordering process for privileged users:
- Adding books to basket
- Authorization
- Calculation of discounts
- 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.