Design Patterns - Pipeline

Pipeline design pattern comes in handy when we need to execute sequences of steps over an input (request), were each step must be handled by differente software logic. For instance, imagine a sequence of steps needed to approve a credit, a sequence of tests scores checking before decide if an student go up a year,medical exams results, etc... Let's dive in a simple credit approval imaginary flow using typescript, you can define your own logic but for the sake of simplicity i'll keep as simple as i can. For this we'll need the following structures: a card issuer represented by the enum CardIssuer, a person (person Interface) and a Credit, see bellow image: So with the basic model defined let's define our Pipeline implementation, for this we will need a CreditCardEvaluation class an interface that defines our handlers (the contract to handle the request), and the pipeline class. Now we must define what we want to valiate/check. For that i defined a basic credit validator (BasicCreditProcessor), a Guarantee Validator and a credit card message processor: Now that we have our structure, let's test it: and the result is: a second test: with the result: by using the pipeline design patter we avoid having a single class with multiple responsabilities and adding more processors "step checker/executors" ares as easy as writing them and placing them inside the pipeline. that is it.

Apr 7, 2025 - 18:07
 0
Design Patterns - Pipeline

Pipeline design pattern comes in handy when we need to execute sequences of steps over an input (request), were each step must be handled by differente software logic.

For instance, imagine a sequence of steps needed to approve a credit, a sequence of tests scores checking before decide if an student go up a year,medical exams results, etc...

Let's dive in a simple credit approval imaginary flow using typescript, you can define your own logic but for the sake of simplicity i'll keep as simple as i can.

For this we'll need the following structures:
a card issuer represented by the enum CardIssuer, a person (person Interface) and a Credit, see bellow image:

Image description

So with the basic model defined let's define our Pipeline implementation, for this we will need a CreditCardEvaluation class

Image description

an interface that defines our handlers (the contract to handle the request), and the pipeline class.

Image description

Now we must define what we want to valiate/check. For that i defined a basic credit validator (BasicCreditProcessor), a Guarantee Validator and a credit card message processor:

Image description

Now that we have our structure, let's test it:

Image description
and the result is:

Image description

a second test:

Image description

with the result:

Image description

by using the pipeline design patter we avoid having a single class with multiple responsabilities and adding more processors "step checker/executors" ares as easy as writing them and placing them inside the pipeline. that is it.