You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pipeline/README.md
+82-6Lines changed: 82 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,83 @@ tags:
9
9
---
10
10
11
11
## Intent
12
-
Allows processing of data in a series of stages by giving in an initial input and passing the processed output to be used by the next stages.
12
+
Allows processing of data in a series of stages by giving in an initial input and passing the processed output to be
13
+
used by the next stages.
14
+
15
+
## Explanation
16
+
17
+
The Pipeline pattern uses ordered stages to process a sequence of input values. Each implemented task is represented by
18
+
a stage of the pipeline. You can think of pipelines as similar to assembly lines in a factory, where each item in the
19
+
assembly line is constructed in stages. The partially assembled item is passed from one assembly stage to another. The
20
+
outputs of the assembly line occur in the same order as that of the inputs.
21
+
22
+
Real world example
23
+
24
+
> Suppose we wanted to pass through a string to a series of filtering stages and convert it as a char array on the last stage.
25
+
26
+
In plain words
27
+
28
+
> Pipeline pattern is an assembly line where partial results are passed from one stage to another.
29
+
30
+
Wikipedia says
31
+
32
+
> In software engineering, a pipeline consists of a chain of processing elements (processes, threads, coroutines, functions, etc.), arranged so that the output of each element is the input of the next; the name is by analogy to a physical pipeline.
33
+
34
+
**Programmatic Example**
35
+
36
+
The stages of our pipeline are called `Handler`s.
37
+
38
+
```java
39
+
interfaceHandler<I, O> {
40
+
Oprocess(Iinput);
41
+
}
42
+
```
43
+
44
+
In our string processing example we have 3 different concrete `Handler`s.
And here's the `Pipeline` in action processing the string.
82
+
83
+
```java
84
+
var filters =newPipeline<>(newRemoveAlphabetsHandler())
85
+
.addHandler(newRemoveDigitsHandler())
86
+
.addHandler(newConvertToCharArrayHandler());
87
+
filters.execute("GoYankees123!");
88
+
```
13
89
14
90
## Class diagram
15
91

@@ -21,16 +97,16 @@ Use the Pipeline pattern when you want to
21
97
* Add readability to complex sequence of operations by providing a fluent builder as an interface
22
98
* Improve testability of code since stages will most likely be doing a single thing, complying to the [Single Responsibility Principle (SRP)](https://java-design-patterns.com/principles/#single-responsibility-principle)
23
99
24
-
## Typical Use Case
25
-
26
-
* Implement stages and execute them in an ordered manner
0 commit comments