One way is to use a BPM however this has boilerplate config/code, a leaner solution is to implement Pipeline Pattern:
Definition of the Pipeline Pattern
Each of the sequence of calculations is performed by having the first stage of the pipeline perform the first step, and then the second stage the second step, and so on.
As each stage completes a step of a calculation, it passes the calculation-in-progress to the next stage and begins work on the next calculation.”
https://www.cise.ufl.edu/research/ParallelPatterns/PatternLanguage/AlgorithmStructure/Pipeline.htm
This is almost the same than:
Pipeline, Pipes and filters:
https://www.enterpriseintegrationpatterns.com/patterns/messaging/PipesAndFilters.html
https://www.codeproject.com/articles/1094513/pipeline-and-filters-pattern-using-csharp
gist:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Step<T> { | |
T process(T input) throws ExecutionException; | |
} | |
public class Pipeline<T> { | |
private final List<Step<T>> steps; | |
public Pipeline(Step<T>... steps) { | |
this.steps = Arrays.asList(steps); | |
} | |
public T process(T input) throws ExecutionException { | |
T processed = input; | |
for (Step<T> step : steps) { | |
processed = step.process(processed); | |
} | |
return processed; | |
} | |
} | |
public class FooStep implements Step<Bar> { | |
public Bar process(Bar em) throws ExecutionException { | |
JSONObject infoGeneral = em.getInfoGneral(); | |
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | |
em.getInfoGneral().put("Date", sf.format(new java.util.Date())); | |
infoGeneral.put("Version", project.getVersion()); | |
infoGeneral.put("Release", "0"); | |
infoGeneral.put("Project", project.getProperties().getProperty("project-name")); | |
return em; | |
} | |
} | |
Main() { | |
Pipeline<Bar> pipeline = new Pipeline<>( | |
new FooStep(), | |
new BarStep(), | |
new QuxStep() | |
); | |
pipeline.process(this); | |
} |
https://stackoverflow.com/questions/39947155/pipeline-design-pattern-implementation