Class Diagram
The class diagram is a static diagram which describes the class structure of an application.
It is the most common starting point for software developers and architects when designing a system.
Class¶
A class is represented with a box containing three parts.
- Name
- Attributes (fields)
- Methods

Visibility¶
We denote the visibility of attributes and methods with the following notations.
| Marker | Visibility |
|---|---|
| + | public |
| # | protected |
| ~ | package |
| - | private |
Attributes (Fields)¶
Attributes are listed by name:Type.
We add a visibility notation before each field.
static fields are underlined.
For the fields
private String str;
protected int intField;
...we write
- str: String
# intField: int
Methods¶
Each method is written using its signature and return type, in the form visibility signature():ReturnType.
Constructors do not list a return type.
For the constructor and methods
public ExampleClass(){
}
public String getStr() {
return str;
}
public void setStr(String str) {
if(str == null) {
str = "";
}
this.str = capitalizeStr(str);
}
private String capitalizeStr(String input) {
return input.toUpperCase();
}
+ ExampleClass()
+ getStr():String
+ setStr(String):void
- capitalizeStr(String):String
Example Diagram¶
Note the private and protected fields, and public and private methods, of this class:
public class ExampleClass {
private String str;
protected int intField;
public ExampleClass() {
}
public String getStr() {
return str;
}
public void setStr(String str) {
if(str == null) {
str = "";
}
this.str = capitalizeStr(str);
}
private String capitalizeStr(String input) {
return input.toUpperCase();
}
}
