The DRY-principle (Don't Repeat Yourself) is a principle in software and data engineering generally and also good to have in mind when designing a solution in Konstrukt. See the example below as an illustration of how to apply this principle in practice.
Requirement
Inputs:
- Salary: Full-Time Equivalent (FTE) salary.
- EmploymentRate: A percentage (0–100%) indicating the employee's workload.
Calculations
- Base Salary Costs:
Salary * EmploymentRate. - Pension Costs:
Salary * EmploymentRate * X, where X is the pension compensation percentage. - Payroll Tax:
Salary * EmploymentRate * Y, where Y is the general payroll tax percentage.
In many cases, there are several calculations like the three above.
Solution
Instead of using Salary and EmploymentRate as direct sources in these calculations, it's possible to create a ValueType (e.g. Salary.Calculated) holding the result of Salary * EmploymentRate. This means that the three calculations above will rather be built as:
- Base Salary Costs:
Salary.Calculated. - Pension Costs:
Salary.Calculated * X, where X is the pension compensation percentage. - Payroll Tax:
Salary.Calculated * Y, where Y is the general payroll tax percentage.
Why is this a good idea?
There are several reasons why this might be a good idea, for example:
- Changes need to be made in fewer places. For example, the employment rate might initially be entered manually per Employee and YearMonth but at some point, the requirement changes and EmploymentRate in the calcualations above shall be deducted with a centrally entered percentage for forecasted sick leave or parental leave. Assuming a solution built like above, this only need to be changed in one calculation (i.e. the one writing to SalaryCalculated) and not in the calculations of salary cost, pension cost, general payroll tax, etc. separately.
- Easier to debug and analyze when the chain of calculations grow larger and more complex.
- Easier for someone trying to do data lineage and understand how a certain number is calculated.