5i. UML Elements - PrimitiveType
We'll continue talking about the other DataType: PrimitiveType.
What is a PrimitiveType?
"A PrimitiveType defines a predefined DataType, without any substructure...The run-time instances of a PrimitiveType are values that correspond to mathematical elements defined outside of UML..."
PrimitiveTypes are DataTypes, but instead of having structure with attributes or operations, they simply instantiate into values. PrimitiveTypes are predefined. This means that normally you wouldn't have the ability to create custom PrimitiveTypes.
PrimitiveTypes are not usually shown in UML Class Diagrams, but when they are, they are shown with Class notation, except without compartments for attributes and operations. They usually have a "«primitive»" keyword above it's name.
UML comes with a set of predefined PrimitiveTypes that we will go over individually.
PrimitiveType: Boolean
"An instance of Boolean is one of the predefined values true and false."
A Boolean simply represents a 1 or 0, on or off, true or false.
You would use this as a "type" of a Property or other typed element like a Parameter when the value is one of only 2 values. If you can ask a yes/no question about the property, it will likely be of the Boolean type. For example "isComplete" or "canBeTransferred" would be best represented as a Boolean.
PrimitiveType: String
"An instance of String defines a sequence of characters."
A String is simply characters. It can be one word, many words, paragraphs, or characters that are put together that are none of those.
You would use this as the "type" of a Property if you need to represent names, descriptions, labels, or any kind of freeform text.
This is probably the most common PrimitiveType.
PrimitiveType: Integer
"An instance of Integer is a value in the (infinite) set of integers (...-2, -1, 0, 1, 2...)."
An Integer is simply a whole number. Integers can be both positive and negative.
You would use this as the "type" of a Property where you want to represent things like counts, quantities, and other numeric values.
PrimitiveType: Real
"An instance of Real is a value in the (infinite) set of real numbers."
A Real is a number that can contain decimals or fractions of numbers. This is known in programming languages as Float, Double, Decimal, and many other things.
You would use this as the "type" of a Property when you need to represent things like costs, quantities, precise dimensions, etc.
PrimitiveType: UnlimitedNatural
"An instance of UnlimitedNatural is a value in the (infinite) set of natural numbers (0, 1, 2...) plus unlimited. The value of unlimited is shown using an asterisk ('*')."
The concept of UnlimitedNatural is a new concept. An UnlimitedNatural represents both a whole number Integer as well as a special value for expressing "many" or "unlimited". So, the possible values can be any Integer value as well as the value "*" (asterisk).
This type doesn't have a lot of applications. But, it can be used to express limits. In particular it's used to indicate the "upperValue" of a multiplicity element like Property or Parameter where the upper limit or bound can be a number or "unlimited"/"many".
Comparison to Object-Oriented Programming Languages
PrimitiveTypes exist in object-oriented programming languages and map very well to the predefined PrimitiveTypes described here. Integers are known as "int", "long", "bigint", etc. Reals are known as "double", "float", "decimal", etc. Strings are known as "string" or "char". Booleans are known as "boolean", "bool", etc. The only one that doesn't map over well is UnlimitedNatural.
Abstract Syntax
To illustrate what a PrimitiveType is, UML provides abstract syntax which we have recreated in UML Class Diagrams.


