section: < previous | next > | | | |
chapter: << previous | next >> |
4.2 Boolean Expressions
Since constraints consists of some kind of logic expressions, these can be combined or altered using boolean operations. Supported are OR, AND, XOR, IMPLIES and NOT. The NOT-operation can be applied to any expression, the other binary operations are used by creating a container for two expressions.
a) Applying NOT to an expression
To demonstrate the usage of the NOT-operation, we apply it on the first example of the previous chapter, again displayed in fig. 4.2.1. If we wan`t to express, that the name of the company should not be GMC (because its a registered trademark an cannot be used by other companies), we add a NOT by opening the context-menu inside the constraint (fig. 4.2.2), and click the un/negate item, which toggles from normal to not and back again, if clicked a second time. The resulting diagram is displayed in figure 4.2.3, the corresponding OCL-Syntax in figure 4.2.4.
|
Fig. 4.2.1 - Example 1: Attribute Navigation
|
Fig. 4.2.2 - Negation using the context-menu
|
Fig. 4.2.3 - Resulting negated expression
|
Fig. 4.2.4 - Resulting OCL-String
b) Boolean Operations
To connect two expressions with a boolean operation like AND, you have to add a boolean container to an existing one. The creation of all binary expressions is very similar, so that only one of them is dicussed here. When having an empty constraint in place, do the following steps to create a boolean expression:- First of all, select the Boolean Expression-Button from among the Container items. Then click inside the constraint-figure, whereupon a dialog appears (see fig. 4.2.5).
- Choose the desired operation type, e.g. AND, and choose the orientation of the two containers by leaving the check-box is vertical selected, what will cause the containers to appear beside each other, or by deselcting it, what will display them among each other.
- Clicking the Enter-Button will create the Boolean Expression with its two nested containers, as displayed in fig. 4.2.6.
|
Fig. 4.2.5 - Dialog for creating a boolean expression
|
Fig. 4.2.6 - Resulting Boolean-Container
c) Subsequent addition of boolean expression
When creating expressions, it could happen, that the diagram does not fit your needs. In the example above, the boolean operation was inserted into an empty constraint. What happens, if the need for such an expression is figured out subsequently? Therefor, the editor provides a possibility to insert them into existing diagrams, overtaking the already drawn figures to the new diagram. To do this, add a boolean expression into an existing diagram, like the one shown in figure 4.2.1. When inserting an AND-Expression to it, two new containers appear, both of them containing the expression previously found in the simple one (see fig. 4.2.7). Deleting the elements from that side, where other expressions should be inserted, is done very fast.
|
Fig. 4.2.7 - Subsequent addition of Boolean Expression
d) Combining NOT and binary operations (AND)
Applying the NOT operation now is possible in two different ways. The first is on a complete boolean expression, the second is on one of the containers of a boolean expression. These two applications are displayed in fig. 4.2.8 and 4.2.9. The editing tasks only differ in the location, where the context-menu is openend. For negating the complete boolean expression, open the context-menu over the headline of the boolean expression (inside the light-blue field, where the name of the operation is displayed). For negating a single container of the boolean expression, use the context-menu inside that container.
|
Fig. 4.2.8 - Negation of the complete Boolean Expression
|
Fig. 4.2.9 - Negation of one part of a Boolean Expression
section: < previous | next > | | | |
chapter: << previous | next >> |