Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.
Prev | Next |
Integrate DMN Module 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:
- Class element
- DMN Model(s)
- DMN Binding to Class & Intelli-sense
- Code Generation on 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:
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. In the 'DMN Complete Example' (Model Patterns), you can see all the more detailed steps.
DMN Model(s)
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.
- 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.
Note: In this example, we focus on how to integrate DMN Modules into a Class Element; the DMN element's detail is not described here. The full example is available in Model Patterns and the EAExample model.
- Generate code for both DMN Models
Click on the System Output window, 'DMN' page:
, and check that you can see this string in theDMN 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 button, 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.
Use the Quick Linker to create a Dependency connector from the Class Applicant to the DMN Artifact.
On creation of the connector, the dialog will prompt you to choose the operation to be bound to the DMN module.
Here is what has happened after the DMN Binding:
- The operation takes a stereotype <<dmnBinding>>
- The Dependency connector is linked to the operation
- Multiple DMN Artifacts can be bound to the same operation
After DMN Bindings, Intelli-sense for the operation's code editor will support DMN Modules. To trigger the Intelli-sense, use these key combinations:
- - in most of the cases
- - 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_DisposibleIncome
- 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'.