Reaves.dev

v0.1.0

built using

Phoenix v1.7.12

OCL

Stephen M. Reaves

::

2023-10-03

Notes about Lesson 8 of CS-6310

Summary

Object Constraint Language

Official part of UML

Provides details that cannot be described by diagrams

Strongly typed, declarative specification of system properties

Constraints + collection classes + UML diagram navigation

Extends UML with:

Overview

Declarative, not procedural

No assignments or other side effects

Strongly typed

Highest level mechanism is constraint

Uses

Syntax

context <identifier> <constraintType>: <Boolean expression>

The context+identifier describe where you are in a diagram, typically a class

Invariants

Statement of a property that is always true

Express key system requirement

inv keyword

context LargeCompany inv: numberOfEmployees > 50

Integrity constraints

Pre and Post conditions

context Real::squareRoot() : Real
pre: self >= 0
post: self = result * result

Changes to Attribute Values

Post conditions can also be used to describe the results of changes in the value of the attribute

context Account::deposit(Real : amount)
pre: amount > 0
post: balance = balance@pre + amount

Built-ins

TypesLiteralsOperations
Booleantrue, falseand, or, xor, not, implies, if-then-else
Integer1, -5, 10000, …*, +, -, /, abs(), …
Real1.5, 3.14, …*, =, -, /, floor(), …
String‘to be or not to be’toUpper(), concat()

KeywordDescription
inv, pre, postIntroduces constraints
if-then-else-endifConditional
not, or, and, xor, impliesBoolean operators
package, endpackagePackages
contextIntroduces constraints
defGlobal definition
let, inlocal definition
deriveAttribute derivation
initIntial value description
resultResult value from an operation
selfObject being constrained

Let clause

Introduces an abbreviation to a constraint

let incoome : Integer = self.job.salary->sum() in
  if isUnemployed then income < 100
                  else income >= 100
  endif

To refer to features of a non-context class, you must use a qualified name

Navigation is done by walking through a diagram from the context class to the other class using intermediary relationship lines and class rectangles

Customer
name
address
Order
date
status
calcTax()
calcTotal()
calcTotalWeight()
context Customer
  self.order.date

Multiplicity means a collection

Collections

Collection
size()
includes()
count()
includesAll()
isEmpty()
notEmpty()
sum()
exists()
forAll()
iterate()
Set
OrderedSet
Bag
Sequence

Other Features