Class Model
Content may include inaccuracies, outdated information, or technical errors. Users are advised to cross-check critical information before implementation.
A class model describes the data of a system: classes, their attributes, the references between classes and the data types the values come from. Multiplicities, value ranges and string patterns are set here as well.
Create two models
Create a model Data Types of the type ClassModel and a second model
Sample. The first holds a vocabulary of data types, the second the classes.
Other models can then use the same types.
Data types are model elements just like classes, so a model may consist of types alone.
The vocabulary of types
Add to Data Types:
- string type
String, boolean typeBoolean, UUID typeUUID; - numeric type
IntegerwithfractionDigits0; - numeric type
UnsignedIntwithsize32andminInclusive0; - temporal type
DatewithinstantUnitsYear,Month,Day.
Add to Sample the two types only it needs: numeric Money (totalDigits
19, fractionDigits 4, minInclusive 0) and enumerated Color with the
literals Red, Green, Blue, Black.
Classes
Add four classes to Sample. A class owns properties, and a property is either
an Attribute with a data type or a Reference to another class. Both have
a multiplicity.
| Class | Properties |
|---|---|
User | firstName, lastName, birthDate [0..1], email [1] |
Order | deliveryAddress String [1] |
OrderItem | quantity UnsignedInt [1], price Money [1] |
Product | abstract, name String [1] |
Add Book with the attribute author and Pen with the attribute color.
Draw Generalization from each to Product.
References
| Owner | Reference | Target | Kind | Multiplicity |
|---|---|---|---|---|
Order | user | User | Association | [1] |
Order | items | OrderItem | Composition | [0..*] |
OrderItem | order | Order | Association | [1] |
OrderItem | product | Product | Association | [1] |
Set items and order as opposite to each other - on the diagram the two
references become the two ends of one edge.
Textual representation
Open the model as text. This is the same model written as source: renaming a class in the text renames it on the diagram.
classModel Sample
class Order {
attribute deliveryAddress String
reference user User
composition items OrderItem [0..*] opposite order
}
abstract class Product {
attribute name String
}
class Book extends Product {
attribute author String
}
enumerated Color {
Red
Green
Blue
Black
}