A UML class is one of the key building blocks to create UML class diagrams.

It is represented as a card with three sections:

Example of a UML class:


classDiagram
	class Dog {
		+String name
		+int age
		+void Bark()
	}

Class Name

Defines the class. Abstract Classes have italicised class names.

UML Attributes

A UML attribute must be defined with a name, and can have optional properties

PropertySyntaxExample
Name
Data TypeName: [Data Type]
Initial valueName: datatype = [Initial val]
Privacy/Visibility Modifier[Privacy symbol] Name ...
+PublicVar

#ProtectedVar
+: Public
~: Default
#: Protected
-: Private
Multiplicity/CountName: Type[Multiplicity]
in some cases
Name[Multiplicity]: Type is used
= Finite
= Finite Range
Unknown Range
= Unknown Range (0+)
Static[Underlined]

UML Diagrams must only use primitive data types

Derived data types must be represented as a Class Relationship as well as the normal text. I.e. if we write name: CustomString, we also need to show a UML class CustomString, and some relationship between the two.

For example:

classDiagram
	class gameObj{
		-xPos: double
		-yPos: double
		-zPos: double = 0.0
		-count: int$
	}
	class Rectangle{
		-width: double
		-height: double
		-x: double = 0.0
		-y: double =0.0
	}

UML Methods

PropertySyntaxExample
Name[Name]()
Privacy[Privacy][Name]()
Return type[Name](): [Type]
Function (Computer Science) parameters[Name]([Parameters])
StaticUnderline
For example:
classDiagram
	class Cube{
		-position[3]: double
		-rotation[3]: double
		-scale[3]: double
		+Resize(newSize[3]: double) void
		+Move(newPos[3]: double) void
	}