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

1

7

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

Porty answered 17/12, 2018 at 18:2 Comment(0)
S
14

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.

Shackle answered 26/12, 2018 at 3:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.