Boolean
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
===== | ===== Definition ===== | ||
A boolean in OCL can be both Non-nullable and Nullable. | A boolean in OCL can be both Non-nullable and Nullable. | ||
NonNullableBoolean : Boolean | NonNullableBoolean : Boolean | ||
NullableBoolean : Boolean? | NullableBoolean : Boolean? | ||
As an attribute on a class that is saved to the database, almost always use '''non-nullable'''. Why? Because otherwise it will default to null and it's easy to | As an attribute on a class that is saved to the database, almost always use '''non-nullable'''. Why? Because otherwise, it will default to null, and it's easy to handle ''False'' and ''Null'' mistakenly and incorrectly. | ||
===== Evaluating ===== | ===== Evaluating ===== | ||
Line 11: | Line 11: | ||
'''not class.BooleanAttribute''' | '''not class.BooleanAttribute''' | ||
Not like this: | |||
class.BooleanAttribute = True | class.BooleanAttribute = True | ||
Line 19: | Line 19: | ||
===== Mistakes We Have Seen Happen ===== | ===== Mistakes We Have Seen Happen ===== | ||
class.BooleanAttribute->notEmpty | class.BooleanAttribute->notEmpty | ||
The expression will always return True because it will be converted to a list with one Boolean | The expression will always return True because it will be converted to a list with one Boolean and that list will never be empty. | ||
[[Category:OCL]] | [[Category:OCL]] |
Revision as of 07:25, 1 August 2023
Definition
A boolean in OCL can be both Non-nullable and Nullable.
NonNullableBoolean : Boolean
NullableBoolean : Boolean?
As an attribute on a class that is saved to the database, almost always use non-nullable. Why? Because otherwise, it will default to null, and it's easy to handle False and Null mistakenly and incorrectly.
Evaluating
Remember to evaluate booleans like this:
class.BooleanAttribute not class.BooleanAttribute
Not like this:
class.BooleanAttribute = True class.BooleanAttribute = False
i.e. without an equal sign and True, False.
Mistakes We Have Seen Happen
class.BooleanAttribute->notEmpty
The expression will always return True because it will be converted to a list with one Boolean and that list will never be empty.
This page was edited more than 11 months ago on 02/10/2024. What links here