Book a Demo

Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Prev Next

Integrate Into UML Class Element

After a Decision Model is created and simulated, you can generate a DMN Module in Java, JavaScript, C++ or C# and test it.

The DMN Module can be integrated with a UML Class element, so the code generated from that Class element can reuse the DMN Module and be well-structured. Since a Class element can define a StateMachine, after integration with the DMN Module the Executable StateMachine simulation will generically be able to use the power of the DMN Module.

In this topic, we will explain the process of integrating a DMN Model with a UML Class element, considering the:

  • Class element's requirement
  • DMN Models
  • DMN Binding to Class & Intelli-sense
  • Code Generation on the Class element

Class Element's Requirement

Suppose we have a Class Applicant with an operation AffordabilityForProduct that evaluates whether the applicant can afford a loan product.

A simplified model resembles this:

A view of Class element to be used for integration with a DMN model using Sparx Systems Enterprise Architect.

The Class Applicant contains two attributes, which are actually calculated from more basic data such as the applicant's monthly income, expenses, existing repayments, age and employment status.

In this example, however, we simplify the model by skipping these steps and providing disposable income and risk score directly.

DMN Models

In this example, we have two disjoint DMN Models to show that a UML Class can integrate multiple DMN Models.

Installment Calculator

This DMN model computes the monthly repayment based on amount, rate and terms. It is composed of an InputData, a Decision and a Business Knowledge Model.

An example of DMN Module showing it in simulation mode using Sparx Systems Enterprise Architect.

Credit Contingency Factor Calculator

This DMN model computes the credit contingency factor based on the applicant's risk score. It is composed of an InputData, two Decisions and two Business Knowledge Models.

An example of DMN Module showing it in simulation mode using Sparx Systems Enterprise Architect.

Note: In this example, we focus on how to integrate DMN modules into a Class element; the DMN elements' detail is not described here.

Generate code for both DMN Models

Click on the Generate Code icon, and check that you can see this string in the System Output window, 'DMN' tab:

DMN Module is successfully compiled.

Note: Since this model uses a built-in function PMT, the DMN Library has to be included:

Click on the Generate Code icon, and check that you can see this string in the System Output window, 'DMN' page:

DMN Module is successfully compiled.

DMN Binding to Class & Intelli-sense

Put the two DMNSimConfiguration Artifacts on the Class diagram.

Integrate a DMN Model and Class Element by placing DMNSimConfiguration artifacts on the class diagram in Sparx Systems Enterprise Architect.

Use the Quick Linker to create a Dependency connector from the Class Applicant to each of the DMN Artifacts.

On creation of the connector, a dialog will prompt you to choose the operation to be bound to the DMN module.

When the DMN module is bound to the operation:

  • The operation takes a stereotype <<dmnBinding>>
  • The Dependency connector is linked to the operation

Multiple DMN Artifacts can be bound to the same operation.

A diagram showing a Class that that is connected to two DMN Simulaiton Artifacts setting the integration of a Class to a DMN module.

After DMN Bindings, Intelli-sense for the operation's code editor will support DMN Modules. To trigger the Intelli-sense, use these key combinations:

  • Ctrl+Space - in most of the cases
  • Ctrl+Shift+Space - when Ctrl+Space does not work after a parenthesis '('; for example, a function's arguments, or inside an 'If' condition's parentheses
  • Class attributes will be listed -  m_RiskScore, m_DisposableIncome
  • Operation parameters will be listed - Amount, Rate, Term
  • Operations will be listed - AffordabilityForProduct
  • All bound DMN Modules will be listed - Contingency_Factor_Calculator, Installment_Calculator

It is quite easy to compose the code with Intelli-sense support. On accessing the DMN Module, all the Input Datas, Decisions and Business Knowledge Models will be listed for selection.

This illustration shows that we are selecting 'Get_Required_monthly_installment()' from the Installment_Calculator.

This is the final implementation for the operation.

Code Generation for Class (With DMN Integration)

'Generate Code on Class Applicant' produces this code:

  • The DMN Module(s) are generated as attributes of the Class
  • The dmnBinding operation's code is updated

Note: Regardless of whether the generation option is 'Overwrite' or' Synchronize', the operation's code will be updated if it has the stereotype 'dmnBinding'.

Learn more