GuardConstraints
(Created page with "Constraints is a good way to add business rules to your application. Constraints are further discussed here. Guards are what you set on UML – State machin...")
 
(Automatically adding template at the end of the page.)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Constraints is a good way to add business rules to your application. [[Constraints|Constraints are further discussed here.]]
Constraints are helpful when adding business rules to your application. [[Constraints|Constraints are further discussed here.]]


Guards are what you set on [[UML – State machines|State machine transitions as described here]].
Guards are what you set on [[UML – State machines|State machine transitions as described here]].


== This article is on GuardConstraints. ==
== GuardConstraints Explained ==
GuardContraints lets you use the Constraints definitions of the class when defining a Guard. In other words GuardConstraints is a way to avoid repetition of rules. You may have constraints (rules on the class) and you may have guards(rules on a class for checking transition of state).
GuardContraints let you use the Constraints definitions of the class when defining a Guard. In other words, GuardConstraints is a way to avoid the repetition of rules. You may have constraints (rules on the class) and guards (rules on a class for checking the transition of state).


The GuardConstraints for a guard is a way to say that one or many of the constraints work as the implementation of the guard.
The GuardConstraints for a guard is a way to say that one or many of the constraints work as the implementation of the guard.


This way rules that must be valid on many transitions can be defined once as a constraint. It is also the best way to let user have insights into why a transition is disabled since Constraints are associated with a message – something that a guard is not.
This way, rules that must be valid on many transitions can be defined once as a constraint. It is also the best way for users to have insight into why a transition is disabled since Constraints are associated with a message – something that a guard is not.


You associate Constraints with transitions to create a GuardConstraint by right clicking the transition on the state diagram – choose Edit GuardConstraints…
You associate Constraints with transitions to create a GuardConstraint by right-clicking the transition on the state diagram – choose Edit GuardConstraints…


@Linus; Prior to versions 2015-03-27 this was not fully implemented – but now it is.
@Linus; Before version 2015-03-27 was not fully implemented – but now it is.


[[File:Constraints - 1.png|frameless|531x531px]]
[[File:Constraints - 1.png|frameless|531x531px]]


Above I add two constraints to the “Thing” class.
Above, I add two constraints to the “Thing” class.


If I now add a state machine – with a transition – I can use these constraints as the guard implementation:
If I add a state machine now – with a transition – I can use these constraints as the guard implementation:


[[File:Constraints - 2.png|frameless|594x594px]]
[[File:Constraints - 2.png|frameless|594x594px]]


Having done this I get this effect:
Having done this, I get this effect:


[[File:Constraints - 3.png|frameless|489x489px]]
[[File:Constraints - 3.png|frameless|489x489px]]


The Constraints show up as broken red – the Trigger1 is disabled (the guard does this).
The Constraints are shown as a broken red – the Trigger1 is disabled (the guard does this).


When I fix one of the constraints:
When I fix one of the constraints:
Line 32: Line 32:
[[File:Constraints - 4.png|frameless|493x493px]]
[[File:Constraints - 4.png|frameless|493x493px]]


The list of errors is reduced but Trigger1 is not available yet.
The list of errors is reduced, but Trigger1 is not available yet.


And fixing the other constraint makes the Trigger1 enabled:
And fixing the other constraint enables Trigger1:


[[File:Constraints - 5.png|frameless|496x496px]]
[[File:Constraints - 5.png|frameless|496x496px]]
[[Category:OCL]]
[[Category:MDriven Designer]]
[[Category:Constraints]]
{{Edited|July|12|2024}}

Latest revision as of 15:35, 10 February 2024

Constraints are helpful when adding business rules to your application. Constraints are further discussed here.

Guards are what you set on State machine transitions as described here.

GuardConstraints Explained

GuardContraints let you use the Constraints definitions of the class when defining a Guard. In other words, GuardConstraints is a way to avoid the repetition of rules. You may have constraints (rules on the class) and guards (rules on a class for checking the transition of state).

The GuardConstraints for a guard is a way to say that one or many of the constraints work as the implementation of the guard.

This way, rules that must be valid on many transitions can be defined once as a constraint. It is also the best way for users to have insight into why a transition is disabled since Constraints are associated with a message – something that a guard is not.

You associate Constraints with transitions to create a GuardConstraint by right-clicking the transition on the state diagram – choose Edit GuardConstraints…

@Linus; Before version 2015-03-27 was not fully implemented – but now it is.

Constraints - 1.png

Above, I add two constraints to the “Thing” class.

If I add a state machine now – with a transition – I can use these constraints as the guard implementation:

Constraints - 2.png

Having done this, I get this effect:

Constraints - 3.png

The Constraints are shown as a broken red – the Trigger1 is disabled (the guard does this).

When I fix one of the constraints:

Constraints - 4.png

The list of errors is reduced, but Trigger1 is not available yet.

And fixing the other constraint enables Trigger1:

Constraints - 5.png

This page was edited 89 days ago on 02/10/2024. What links here