Boolean
(Created page with "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 database, almost...")
 
No edit summary
Line 1: Line 1:
===== Defining =====
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
Line 4: Line 5:
  NullableBoolean : Boolean?
  NullableBoolean : Boolean?
As an attribute on a class that is saved to database, almost always use '''non-nullable'''. Why? Because otherwise it will default to null and it's easy to by mistake not handle False and Null correctly.
As an attribute on a class that is saved to database, almost always use '''non-nullable'''. Why? Because otherwise it will default to null and it's easy to by mistake not handle False and Null correctly.
===== 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 will be converted to a list with one Boolean in it, and that list will never be empty.

Revision as of 16:14, 12 September 2021

Defining

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 database, almost always use non-nullable. Why? Because otherwise it will default to null and it's easy to by mistake not handle False and Null correctly.

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 will be converted to a list with one Boolean in it, and that list will never be empty.

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