I'm developing a backend service that is supposed to process items in a pipeline-fashion. Each stage is essentially a
Function<IN, OUT>. So the current stage's input is the previous stage's output. Moreover, each stage needs to write it's result to the
Record object and each stage can get the previous results (not only the previous one)
The problem with this solution is that we break somewhat crucial rule - Immutability. This
Record object is being built one step at a time but it comes with the risk that the state (=the model) is shared between all stages.
So I thought about three options:
- Accept the limit that a stage can't access the
Recordbut rather only get as input the previous result
- Limit the
settersto package-level access modifier a stage can only get data but not to set (and hopefully the data itself is immutable too)
- Accept the risk of mutability
So what do you think is the right design for my problem?