Kengkaj Sathianpantarit wrote:Could you please to give some example code of what you're trying to do?
Sure. Glad you asked.
I'm implementing this TaskChain as a chain of responsibility pattern :
T1 -> T2 -> T3 -> ... -> Tn
Each task does a specific processing on its inputs (say BillingInfo).
I'm outsourcing all the configuration of the task (Tn) objects, chain list piping and configuration to Spring. Thus, a task would be a bean configured via spring to form the chain.
Now, lets say there is a task that needs to performed on the basis of some state that the executor of this chain will initialize. Lets say this state information is "account type". Depending on the account type the tasks process inputs differently. Hence, there could be a task which needs to do this :
1.> if the account type is X, validate BillingInfo to not have Y
2.> if the account type is A, validate BillingInfo to have B & C
Now one solution is to implement a single task, and do the above if-then-else in it. I dont quite like this.
Other solution is to implement 2 separate tasks that just do the above and instantiate the correct one (and pipe it in the chain) depending the state (account type). That's what this question is about.
Thanks for reading & helping!
BTW the use cases above are not what I'm actually going to do - its just to convey my intention