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:
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.
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 elements' detail is not described here.
Generate code for both DMN Models
Click on the System Output window, 'DMN' tab:
, 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 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.
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.
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_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'.