Typed Elements
A second basic building block for UML diagrams is a typed element. Typed elements (as you might expect from the name) have a type. Fields and parameters are typed elements, as are method parameters and return values.
The pattern for defining a typed element is:
$$ \texttt{[visibility] element : type [constraint]} $$The optional $\texttt{[visibility]}$ indicates the visibility of the element, the $\texttt{element}$ is the name of the typed element, and the $\texttt{type}$ is its type, and the $\texttt{[constraint]}$ is an optional constraint.
Visibility
In UML visibility (what we would call access level in C#) is indicated with symbols, i.e.:
- $\texttt{+}$ indicates
public
- $\texttt{-}$ indicates
private
- $\texttt{#}$ indicates
protected
I.e. the field:
protected int Size;
Would be expressed:
$$ \texttt{# Size : int} $$Constraints
A typed element can include a constraint indicating some restriction for the element. The constraints are contained in a pair of curly braces after the typed element, and follow the pattern:
$$ \texttt{ {element: boolean expression} } $$For example:
$$ \texttt{- age: int {age: >= 0}} $$Indicates the private variable age
must be greater than or equal to 0.