(Adding message template to the top of the page) |
(Updated Edited template to July 12, 2025.) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<message>Write the content here to display this box</message> | |||
The "Or" operator evaluates to true if at least one of its operands is true, and false otherwise. It can be used to express a disjunctive relationship between two conditions or requirements. For example, if "a" and "b" are Boolean expressions, then "a or b" will be true if either "a" or "b" (or both) are true. | The "Or" operator evaluates to true if at least one of its operands is true, and false otherwise. It can be used to express a disjunctive relationship between two conditions or requirements. For example, if "a" and "b" are Boolean expressions, then "a or b" will be true if either "a" or "b" (or both) are true. | ||
== Examples: == | |||
'''1.''' Suppose we have a class called <code>Person</code> with the attribute <code>age</code>. We want to define a constraint that allows persons who are either at least 18 years old or have a valid driver's license to drive a car. The OCL expression for this constraint would be: | '''1.''' Suppose we have a class called <code>Person</code> with the attribute <code>age</code>. We want to define a constraint that allows persons who are either at least 18 years old or have a valid driver's license to drive a car. The OCL expression for this constraint would be: | ||
Line 16: | Line 16: | ||
[[Category:OCL Boolean Operators]] | [[Category:OCL Boolean Operators]] | ||
{{Edited|July|12| | {{Edited|July|12|2025}} |
Latest revision as of 05:55, 20 January 2025
The "Or" operator evaluates to true if at least one of its operands is true, and false otherwise. It can be used to express a disjunctive relationship between two conditions or requirements. For example, if "a" and "b" are Boolean expressions, then "a or b" will be true if either "a" or "b" (or both) are true.
Examples:
1. Suppose we have a class called Person
with the attribute age
. We want to define a constraint that allows persons who are either at least 18 years old or have a valid driver's license to drive a car. The OCL expression for this constraint would be:
context Person
(self.age >= 18) or self.hasDriverLicense
This constraint specifies that the age
attribute of a person object must be greater than or equal to 18, or its "hasDriverLicense" attribute must be true for the object to satisfy the constraint. If a person is at least 18 years old or has a valid driver's license, then they are allowed to drive a car.
2. Consider a class called Product
with two attributes: name
and category
. We want to define an operation that returns true if a product belongs to either the "Electronics" category or the "Books" category. The OCL expression for this operation would be:
context Product
is_interesting = (self.category = 'Electronics') or (self.category = 'Books')
This expression uses the "Or" operator to combine two conditions that check whether the category
attribute of a product object is equal to either "Electronics" or "Books". If either condition is true, then the is_interesting
variable is set to true, indicating that the product is interesting.