If you've ever stared at a blank diagram tool wondering whether an arrow should have a hollow triangle or a filled diamond, you already know why a UML class diagram syntax cheat sheet matters. Class diagrams are the backbone of object-oriented design they show your classes, their properties, methods, and how everything connects. But the notation has a lot of small details that are easy to forget or mix up. This reference breaks down the exact syntax so you can build accurate diagrams without second-guessing every line.
What does UML class diagram syntax actually cover?
UML class diagram syntax defines how you visually represent classes, attributes, methods, visibility, and the relationships between objects. It's a standardized notation created by the Object Management Group (OMG). When people search for a class diagram syntax cheat sheet, they usually need a quick-reference for one or more of these elements:
- How to write class names, attributes, and operations in the correct format
- What visibility markers (+, -, #, ~) mean
- How to draw associations, inheritance, composition, and aggregation
- Multiplicity notation (1, 0..1, , etc.)
- Stereotypes, abstract classes, and interfaces
Developers, software architects, and students use this syntax during system design, code reviews, documentation, and exam preparation. If you're documenting a codebase or planning a new feature, a correct class diagram saves hours of miscommunication.
How is a single class represented in a UML class diagram?
Every class in UML is drawn as a rectangle divided into three compartments:
- Top compartment Class name (bold or underlined if it's abstract)
- Middle compartment Attributes (fields, properties)
- Bottom compartment Operations (methods, functions)
Here's the standard syntax for an attribute:
visibility name : type [multiplicity] = default
And for an operation:
visibility name(parameter: type) : return type
For example, a class might look like this in text notation:
Customer - name: String - email: String - orders: Order[] + getName(): String + addOrder(order: Order): void
The minus sign before name means it's private. The plus sign before getName() means it's public. These visibility markers are one of the most referenced items in any class diagram cheat sheet.
What do the visibility symbols mean?
UML uses four standard visibility markers to show access levels. These map closely to most object-oriented languages:
+(public) Accessible from anywhere-(private) Accessible only within the class itself#(protected) Accessible within the class and its subclasses~(package) Accessible within the same package or module
If you forget the tilde for package visibility, you're not alone it's the least-used symbol and the one most people look up first.
How do you draw relationships between classes?
This is where most people need the cheat sheet the most. UML class diagrams use different line styles and arrowheads to represent different types of relationships. Each one has specific syntax.
Association
A basic association is a solid line between two classes. You can add role names, multiplicity, and direction.
- Syntax: Solid line, optional arrowhead for direction
- Example:
Customer Orderwith multiplicity1on the Customer side andon the Order side
Inheritance (Generalization)
Inheritance uses a solid line with a hollow triangle arrowhead pointing to the parent class.
- Syntax:
ChildClass ▷ ParentClass - The hollow triangle always points from subclass to superclass
Realization (Interface Implementation)
When a class implements an interface, the line is dashed with a hollow triangle pointing to the interface.
- Syntax:
ConcreteClass - - -▷ «interface» InterfaceName
Dependency
A dependency means one class uses another temporarily as a method parameter, local variable, or return type. It's shown as a dashed line with an open arrowhead.
- Syntax:
ClassA - - -> ClassB
Aggregation
Aggregation is a "has-a" relationship where the child can exist independently. It uses a hollow diamond on the side of the whole.
- Syntax:
Team ◇ Player - The diamond attaches to the class that "contains" the other
Composition
Composition is a stronger form of aggregation. The child cannot exist without the parent. It uses a filled diamond.
- Syntax:
House ◆ Room - If the house is destroyed, the rooms go with it
This table summarizes the key relationships visually:
- Association: Solid line →
- Generalization: Solid line with hollow triangle ▷
- Realization: Dashed line with hollow triangle - -▷
- Dependency: Dashed line with open arrow - - >
- Aggregation: Solid line with hollow diamond ◇
- Composition: Solid line with filled diamond ◆
For other UML diagram types that use different notations, our use case diagram notation guide covers the actor and system boundary syntax separately.
How do you write multiplicity correctly?
Multiplicity tells you how many instances of one class can be linked to instances of another. You place it near the end of the association line, on each side. Common values:
1Exactly one0..1Zero or one (optional)or0..Zero or more1..One or more3Exactly three2..5Between two and five
A typical example: a Customer places 1.. orders, and each Order belongs to exactly 1 customer.
How do you show abstract classes and interfaces?
Both abstract classes and interfaces have specific syntax rules:
- Abstract class: The class name is written in italic text. You can also add
{abstract}below the name. Methods that are abstract are also italicized. - Interface: Prefixed with the stereotype
«interface»(or<<interface>>in text tools). Drawn with a dashed line and hollow triangle to the implementing class.
Example of an abstract class in text notation:
Shape {abstract}
- color: Color
+ area(): double {abstract}
+ draw(): void
If you work with state-based behavior in your classes, the UML state machine diagram syntax complements class diagrams by showing how objects transition between states.
What are stereotypes and how do you use them?
Stereotypes extend UML's built-in vocabulary. They appear between guillemets (double angle brackets) above or before an element name. Common stereotypes in class diagrams:
«interface»Marks a class as an interface«enumeration»Marks a class as an enum«abstract»Marks a class as abstract (alternative to italicizing)«utility»A class with only static members«entity»,«service»,«controller»Common in layered architecture diagrams
You can define custom stereotypes when the standard set doesn't cover your needs.
What are the most common mistakes in class diagram syntax?
After reviewing many diagrams from students and working developers, these errors come up repeatedly:
- Swapping aggregation and composition diamonds. Remember: hollow diamond (◇) = aggregation (child can exist alone); filled diamond (◆) = composition (child cannot).
- Arrow direction on inheritance. The hollow triangle always points toward the parent/superclass, not the child.
- Using solid lines for realization. Interface implementation requires a dashed line, not solid.
- Forgetting multiplicity. An association line without multiplicity is ambiguous. Always specify it.
- Mixing up attribute and method syntax. Attributes have no parentheses. Methods do. This sounds obvious but gets mixed up in hurried whiteboard sessions.
- Putting too much detail in every class. You don't need every getter and setter. Show only what's relevant to the purpose of the diagram.
Quick-reference cheat sheet: class diagram notation
Here's a condensed reference you can bookmark or print:
Class structure:
- Class name: ClassName
- Attribute:
visibility name: Type - Method:
visibility name(params): ReturnType
Visibility:
+public,-private,#protected,~package
Relationships:
- Association: solid line
- Directed association: solid line + open arrow →
- Inheritance: solid line + hollow triangle ▷
- Realization: dashed line + hollow triangle - -▷
- Dependency: dashed line + open arrow - - >
- Aggregation: solid line + hollow diamond ◇
- Composition: solid line + filled diamond ◆
Multiplicity:
1,0..1,,1..,n..m
Special elements:
- Abstract class: italic name or
{abstract} - Interface:
«interface»stereotype - Static member: underlined
- Enumeration:
«enumeration»stereotype
While class diagrams focus on structure, you'll often pair them with behavioral diagrams. Our sequence diagram syntax guide covers how to show object interactions over time.
Tips for creating clear, useful class diagrams
- Start with domain classes, not every class in your codebase. A diagram with 50 boxes is unreadable. Focus on the classes that matter for the specific feature or system you're designing.
- Use consistent naming. Pick either PascalCase or a naming convention your team agrees on, and stick with it.
- Group related classes visually. Most UML tools let you add packages or notes to cluster related classes.
- Label association lines. A line between
CustomerandOrdermeans nothing without a label like "places" or a role name like "buyer." - Review with your team. A diagram that makes sense only to you defeats the purpose of communication. Walk through it before moving to code.
- Keep it up to date. An outdated diagram is worse than no diagram. Treat it like code version it and review it.
Your next step: build a class diagram for something real
The best way to internalize UML class diagram syntax is to use it. Pick a small, familiar system a library checkout, a shopping cart, a task manager and draw the classes by hand or in a free tool like PlantUML, draw.io, or Mermaid. Use the cheat sheet above as your reference. Check your work against the syntax rules until the notation feels automatic.
Checklist before you share a class diagram:
- ☐ Every class name is spelled correctly and follows your naming convention
- ☐ Attributes and methods show the right visibility symbol
- ☐ Relationships use the correct line style (solid vs. dashed) and arrowhead
- ☐ Multiplicity is labeled on both ends of every association
- ☐ Abstract classes are italicized; interfaces have the «interface» stereotype
- ☐ Association lines have descriptive labels or role names
- ☐ The diagram tells a clear story without requiring you to explain every box
Print the cheat sheet, tape it next to your monitor, and stop Googling mid-diagram. You've got the syntax now go draw something useful.
Uml State Machine Diagram Syntax Specification Guide
Plantuml Syntax for Activity Diagram Examples
Uml Use Case Diagram Not
Sequence Diagram Syntax Reference Guide
Flowchart Code Script Examples for Software Developers Guide
Mermaid Flowchart Syntax Reference Guide - Complete Code Scripts