Prev | Next |
Integrate DMN Module Into UML Class Element
After a Decision Model is created, simulated, the user may generate a DMN Module in language Java/JavaScript/C++/C# and get it tested.
This DMN Module can be integrated into UML class element so the code generated from the class element can reuse the DMN model and be well structured. Since a class element may define statemachine(s), after integration with DMN module, the executable statemachine simulation will generically be able to use the power of DMN module.
In this page, we will go through a whole process to integrate a DMN Model to a UML Class element:
- Class Element
- DMN Model(s)
- DMN Binding to Class & IntelliSense
- Code Generation on Class Element
Class Element's Requirement
Suppose we have a class Applicant with an operation AffordabilityForProduct, which evaluate whether the applicant can afford a loan product.
A simplified model looks like this:
The class Applicant contains 2 attributes, which is actually calculated from more basic data like applicant's monthly income, expense, existing repayment, age, employment status etc.
In this example, however, we simplify the model by skipping these steps and providing disposible income and risk score directly. In the DMN Complete Example (Model Patterns), you can see all the thorough steps.
DMN Model(s)
In this example, we have 2 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 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 Module into Class Element, the DMN Element's detail is not described in this page. The full example is available in Model Patterns and EAExample model.
- Generate code for both DMN Models
Click "Generate" button, ensure you can see the following string in the System Output window, DMN Page:
DMN Module is successfully compiled.
Note: Since this model uses a built-in function PMT, the DMN Library need to be included:
Click "Generate" button, ensure you can see the following string in the System Output window, DMN Page:
DMN Module is successfully compiled.
DMN Binding to Class & IntelliSense
Put the two DMNSimConfiguration artifacts on the class diagram
Use the quick linker to create a Dependency connector from Class Applicant to the DMN Artifact.
On the connector's creation, the dialog will prompt for the user to choose the operation which will be bound to DMN module.
Here is what's happened after the DMN Binding:
- The operation will be be applied a stereotype "dmnBinding"
- The dependency connector is connecting to the operation
- Multiple DMN Artifacts can be bound to the same operation
After DMN Bindings, IntelliSense for Operation's code editor will support for DMN Modules, the trigger the IntelliSense, use the following key combination:
- + Space: For most of the cases
- Ctrl + + Space: When "Ctrl + Space" does not work after a parenthesis "(". For example, function's arguments, inside if condition's parenthesis, etc.
- Class attributes will be listed: m_RiskScore, m_DisposibleIncome
- Operation Parameters will be listed: Amount, Rate, Term
- Operation 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 IntelliSense support. On accessing the DMN Module, all the Input Datas, Decisions, Business Knowledge Models will be listed for the user to choose.
This figure shows that we are selecting Get_Required_monthly_installment() from Installment_Calculator.
Here is the final implementation for operation.
Code Generation for Class (With DMN Integration)
Generate Code on class Applicant, here is the code generated:
- The DMN Module(s) are generated as attribute of class
- The dmnBinding operation's code is updated
Note: No matter the generation option is Overwrite or Synchronize, the operation's code will be updated if it has a stereotype dmnBinding.
Learn more