Can we use a Single delegate per BPMN process

Hi Team,

can we create and use a singe delegate class per BPMN process having multiple service tasks. for example i have a process with 3 service tasks and 2 user tasks and i have created just one delegate class to implement all three service tasks with different methods.

i just wanna know that - is it the best practice to having one delegate class per service task or we can use single delegate for all the service tasks in process.

I am attaching my BPMN process and delegate, please advise and provide the best practices

Thanks,
KrishanTestProcess.bpmn (7.8 KB) TestDelegate.txt (1.2 KB)

It’s possible, by simply pointing to the same delegate class or delegate expression in the BPMN. In some process models, you have the same implementation in two places, where you can’t reuse the service task in the flow for some reason, so in that case it makes complete sense to do. As a general rule of thumb though, I’d not try to implement all different service tasks in the same delegate method, because if the tasks are really doing different things, it’s easier to program and to maintain if the “glue code” is also separated by the different types of task. Just as you wouldn’t implement all the actions a program can do in one method, even though you could, but it would lead to a code base that is hard to maintain.

3 Likes

Hi @gaur.kk,

additionally to @tiesebarrell’s answer: it’s all a matter of maintenance.

  • How many people work on a single process?
  • How many different processes do you expect in the end?
  • Where and how will they run in production?

Answers to these questions may lead to a decision about how to structure the delegate code.

Hope this helps, Ingo

3 Likes

Hi Ingo,
Please find the answers below: Hope it will help. i am looking for best practices. And also Pros and Cons of this approach.

Hi @gaur.kk,

So the developer can decide on the design of the delegates. But you should set some guidelines, as “people leave the company, software will stay”.

Do you plan to automate only a single process and you end up with a single project? Or do you plan to automate more processes in the future? In this case you should consider the chance of reusing delegate implementations for these processes. Otherwise, keep it simple.

This will give each team a lot of independence (if you provide separated databases for each Microservice)

You should balance the benefits of all implemenations in a single class against reusabilty. For small teams it didn’t make sense to enforce a huge class structure, but keep an eye on maintainability.

Hope this helps, Ingo