(Created page with "This operator is represented by the keyword "or" and evaluates to true if at least one of its operands is true. For example, if "a" and "b" are Boolean expressions, then "a or...") |
(Automatically adding template at the end of the page.) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
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: | |||
context Person | |||
(self.age >= 18) or self.hasDriverLicense | |||
This constraint specifies that the <code>age</code> 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 <code>Product</code> with two attributes: <code>name</code> and <code>category</code>. 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 <code>category</code> attribute of a product object is equal to either "Electronics" or "Books". If either condition is true, then the <code>is_interesting</code> variable is set to true, indicating that the product is interesting. | |||
[[Category:OCL Boolean Operators]] | [[Category:OCL Boolean Operators]] | ||
{{Edited|July|12|2024}} |
Latest revision as of 15:39, 10 February 2024
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.