Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of using expression Delegates over Java classes?

Are there some benefits to use expression delegate over java class in camunda

like image 882
Paul Guey Avatar asked Dec 17 '18 18:12

Paul Guey


People also ask

What is the difference between a Java class and a delegate expression when choosing an implementation for a service task?

The class attribute for the Service Task is the FQN of the class that implements JavaDelegate . When this is used Flowable will instantiate the class. A delegate expression is an expression that resolves a bean that implements JavaDelegate .

What is a delegate class in Java?

Delegation means hand over the responsibility for a particular task to another class or method. It is a technique where an object expresses certain behavior to the outside but in reality delegates responsibility for implementing that behaviour to an associated object.

What is a delegate in Camunda?

A Java Delegate is a simple Java class that implements the Camunda JavaDelegate interface.

What is delegate execution in Java?

DelegateExecution. getSuperExecution() In case this delegate execution is the process instance execution and this process instance was started by a call activity, this method returns the execution which executed the call activity in the super process instance.


1 Answers

Only thing I can imagine using expression delegates over Java classes is that, whenever my custom code class required to load from spring beans using dependency injection, specially where you want to control the lifecycle of delegation instance by your application, not Camunda runtime engine.

In simple words, by using expression delegates, we can initialize the delegate class as we want using spring DI without letting Camunda engine to initialize it. And take all advantages of DI.

The scenario is that we want to load our delegation class from spring beans, where it requires runtime dependencies to be injected before our delegation code runs. So, we can use spring beans to initialize other object dependencies and create a bean referencing the delegation class injecting other initialized beans. For example,

<serviceTask id="paymentTask" camunda:delegateExpression="${myPaymentBean}" />

In above, myPaymentBean is resolved from spring and it will be an instance of JavaDelegate which has already initialized with required dependencies through dependency injection (DI). We used DI, because our business logics needs to be tested thoroughly before going into production and easier to write automated tests on top of them.


If you use Java classes, then the instance initialization part will be done by the camunda engine, and there is a restriction that there must be a public default constructor. This is very limited since most of practical applications have dependencies and must be already initialized before the code. Either you have to make your dependencies as singletons (which is I never recommend) or use factories to create instances before code (which is inefficient and harder to test).

Hope this clarifies your question.

like image 177
isuru89 Avatar answered Oct 07 '22 18:10

isuru89