Hans Karlsen (talk | contribs) No edit summary |
Hans Karlsen (talk | contribs) No edit summary |
||
Line 37: | Line 37: | ||
Constraints automatically show up in ViewModels - but you may opt them out on a per viewmodel level: | Constraints automatically show up in ViewModels - but you may opt them out on a per viewmodel level: | ||
[[File:2021-04-08 10h46 32.png|none|thumb|484x484px]] | [[File:2021-04-08 10h46 32.png|none|thumb|484x484px]] | ||
You can also access Constraints and their "brokeness" via ocl operators borkenConstraints and Constraints: | You can also access Constraints and their "brokeness" via ocl operators borkenConstraints and [[OCLOperators constraints|Constraints]]: | ||
[[File:2021-04-08 10h48 43.png|none|thumb|454x454px]] | [[File:2021-04-08 10h48 43.png|none|thumb|454x454px]] | ||
[[Category:UML]] | [[Category:UML]] |
Revision as of 08:50, 8 April 2021
There are other ways to introduce business rules in the model than using state machines and guards. You can use constraints.
The model already has a lot of implicit constraints from the cardinalities of the association ends. Like if you have cardinality 1..4 and you have zero objects in that relation – then you have broken constraint.
Define constraints
But you may also define you own constraints:
You can choose if a broken constraint (a constraint that evaluates to false) should be treated as Information, Warning or a Error to the user.
Delete constraints
You can also define the constraint as being a delete constraint only:
This way have explained at the model level that the domain does not consider it to be ok to delete a Car-object as long as we have the deposit – unless it is in state Scrapped.
The delete constraints will be checked when is Deleted by MDriven – as a result of the Delete operator is executed on the class.
Other things that are checked when the Delete operator is run are the BusinessDeleteRules that exists on all association endpoints:
We as modelers should decide what the best rule is for each association end. In this case – is it ok to delete a Brand if there are Cars left in the AllCarsOfThisBrand association? No I think not. I am setting it to “MustBeEmpty”.
The association in the other direct on the other hand
I set that to “NeedNotBeEmptyNoWarning” – because deleting a car-object is ok even if it has a brand.
Constraints evaluation in OCL
If you want to evaluate constraints in OCL, use OCLOperators constraints for example.
Usage of constraints
Constraints automatically show up in ViewModels - but you may opt them out on a per viewmodel level:
You can also access Constraints and their "brokeness" via ocl operators borkenConstraints and Constraints: