Relationships
Relationships show associations between different types of classes. For example a class named car has a relationship with a class named wheel.
Last updated
Was this helpful?
Relationships show associations between different types of classes. For example a class named car has a relationship with a class named wheel.
Last updated
Was this helpful?
A basic relationship contains two entities and a line showing the relationship between them.
Relationships are comprised of three parts. Label is the only optional part.
entity - the object for which a relationship can be described in a class diagram, must have at least two
connection - visual description of the relationship between entities
label - textual description of the relationship between entities
The connected entity can be a class, attribute, or method. Classes are defined by their name. Attributes and methods are defined by the class name that contains them followed by two colons (::) and the attribute or method text.
class
attribute
method
Though it comes last in syntax we will explain label before connection. This is a purely aesthetic issue. While label is not required much of the connection is drawn poorly if there is no label. It gets squished together.
label_text - the text describing the relationship between connected entities
read_direction - shows the direction a relationship is read
This text describes the relationship between the connected entities. Label_text is not required even if read_direction is used. You can format label_text with creole syntax for emphasis and markup language for color and emphasis. You can define colors with a standard color name or hex code.
A greater than or less than sign (><) used to show the direction a relationship is read. The sign may be placed before or after the label. Read_direction is not required even if label_text is used.
The connection is the line between the entities. It can carry a lot of information. The only required portion of the connection is the dash (-) between the entities.
multiplicity - defines number relationships between the entities, one may be on each end of the connection
arrowhead - determines the shape of the arrow head, one may be on each end of the connection
line_type - determines the type of line between the entities
line_orientation - determines the direction of the second entity in relation to the first entity
line_color - determines the color of the line making the connection
line_thickness - determines the thickness of the line between the entities
Multiplicity defines number relationships between the connected entities. Multiplicity can exist on each end of the connection. It is written as a number or numbers between quotation marks. You can format multiplicity with creole syntax for emphasis and markup language for color and emphasis. You can define colors with a standard color name or hex code. In this example one car has between four and six wheels.
The connection can have an arrowhead on both ends. It must touch the dash that defines the connection.
Line_orientation determines the placement of a class in relation to the connected class. There are two options, default and relative directions.
By default a single dash in the connection draws the relationship horizontally. Two dashes draws the relationship vertically. These are read left to right and then drawn from left to right and top to bottom.
Relative directions are defined by always using two dashes for the connection and writing the relative direction between the dashes. These are read from left to write and then drawn in the relative direction.
The line_type can change the connecting line to dashed or dotted. Line_type is placed inside of square brackets inside of the connecting dashes. Line_type, line_color and line_thickness can be placed in any order inside of the square brackets they are separated by commas.
The line_color changes the connecting line's color. Line_color is placed inside of square brackets inside of the connecting dashes with a hash symbol (#) before the color. You can define colors with a standard color name or hex code. Line_type, line_color and line_thickness can be placed in any order inside of the square brackets they are separated by commas.
The line_thickness changes the connecting line's width. Line_thickness is placed inside of square brackets inside of the connecting dashes. Line_type, line_color and line_thickness can be placed in any order inside of the square brackets they are separated by commas.
Some relationships can be written as the class is declared. These written relationships are "extends" and "implements."
Note: The following example will be shown with two dashes in the code to provide better aesthetics for the example image. See for further explanation.