UML Component Diagram
To create a UML component diagram, use the componentDiagram function with component elements:
componentDiagram {
// define elements
}Elements
component
Creates a new component element, supporting features similar to classes:
Class Features
For details, see UML Class Diagram
- Properties and Methods: Define public, private, protected, package, or default sections for properties and methods, just like in class diagrams.
- Abstract & Keywords: Use
abstract = trueto mark a component as abstract, andkeywords = list("stereotype")to add stereotypes or keywords in guillemets (« »).
Nesting
Components can contain other components, classes, or interfaces, allowing for hierarchical organization:
Ports
Components can have ports, which are connection points for interfaces or other elements. Ports can be defined inside the component block or using dot notation outside:
Ports can also have interfaces (see below).
Required and Provided Interfaces
Components can declare required and provided interfaces using the provides and requires functions. These can be placed inside the component or attached to ports:
- Syntax:
provides([name], pos, [target], dist = dist, namePos = [x, y])requires(pos, [target])- All arguments are optional.
nameis the interface name (can be omitted).posis the relative position on the component outline (0 = top, 0.5 = right, etc.).targetcan be used for directly connected notation.distcontrols the distance of the interface symbol from the component.namePoscan adjust the label position.
Example for directly connected notation:
Interfaces can also be attached to ports:
Connections / Associations
dependsOn
Instead of directly connecting a required to a provided interface, a dependsOndashed arrow can be used:
WARNING
This connection operator is only supported for connecting required to provided interfaces, the layout will be incorrect for all other uses. Also, do not use the ..> operator for this use case.
Further Connections
For additional connection types (associations, aggregations, etc.), refer to the class diagram documentation.
Config properties
The following config properties are available for class diagrams:
| Variable | Meaning | Default value (in pixels) | Comment |
|---|---|---|---|
abstractAsProperty | Whether to show { abstract } after the name of abstract classes | false | - |
providesDistance | Default distance of provided interfaces to the classifier outline | 100 | - |
requiresDistance | Default distance of required interfaces to the classifier outline | 100 | - |