UML Class Diagram
To create a UML class diagram, one uses the classDiagram
diagram function:
classDiagram {
// define elements
}
Elements
The following elements are supported:
class
Creates a new class element, with the defined name, and optional properties and operations:
Note that properties and functions are defined declaratively, and are not executable code. Thus, e.g. if x
is a defined variable, the property is still named x
, not the value of x
. Five different types of visibility are supported:
public
private
protected
package
default
(no visibility)
In addition, by providing named arguments abstract
or private
to the scope function call, inner entries are in italics / underlined respectively:
Using the section
function, one can also add another section to the body of the class:
To simplify using classes later in the diagram, class
automatically sets itself on the current scope if the variable is not yet defined:
Abstract
To mark a class as abstract, one can use the abstract
named argument:
Keywords
The keywords
named argument can be used to add keywords or stereotypes in guillemets («
and »
):
Nesting
Classes can now contain other classes as nested elements, allowing for a more organized hierarchy:
The nested class is scoped within its parent class and will be visually displayed inside the outer class.
Ports
Classes can now have ports, which are connection points on the class boundary. Ports can be defined either inside the class block or using dot notation outside the class:
For more details, see UML Component Diagram
interface
Creates a new interface element. Identical to class
, however automatically adds the «interface»
keyword.
enum
Creates an enumeration class. Enums are a special type of class and support all class functionality. You can define enum entries using the entries
block:
This is equivalent to creating a class with the "enumeration" keyword:
Enums can also have additional properties and methods like regular classes:
package
Creates a UML package with a name
Packages can contain nested elements, similar to classes:
The nested elements are scoped within the package and will be visually displayed inside the package.
comment
Allows creating UML comments:
Connections / Associations
Connections / Associations are created using a PlantUMl-inspired operator syntax. Both sides of the operand can be either points, or canvasElemments, and thus classes, interfaces, packages or comments. The following operators are supported:
--
for a simple association--*
for a composition--<>
for an aggregationextends
for a generalizationimplements
for an implementation..>
for a dependency--!
for an association not-navigatable in one direction-->
for an association navigatable in one direction- ... and several combinations of the above, e.g,
!--!
,*-->
, ...