Reference · UML 2.5.1
Class diagram symbols: relationships, arrows and visibility
In short
A UML class diagram has two kinds of symbol. Classifiers are boxes: a class is a rectangle with three compartments (name, attributes, operations), an interface or enumeration is the same box with a «stereotype» above the name, and an abstract class has its name in italics. Relationships are the lines between boxes, and the line end tells you which one: plain line = association, open arrowhead = navigable association, hollow diamond = aggregation, filled diamond = composition, hollow triangle = generalisation (inheritance), dashed line with hollow triangle = realisation (implements), dashed line with open arrowhead = dependency. The visibility marks + − # ~ in front of a member mean public, private, protected and package, and the numbers at a line end (1, 0..1, *, 1..*) are the multiplicity. Notation per UML 2.5.1 (OMG formal/2017-12-05).
Updated · by the ChartCraft team · Simbol class diagram (Bahasa Indonesia)
What are the class diagram symbols for classes, interfaces and members?
Every classifier is a rectangle. What changes is the text inside: a stereotype in guillemets above the name, italics for abstract, underlining for static. Mermaid's classDiagram writes the same things with annotations such as <<interface>>.
| Symbol | Element | Notation | Mermaid |
|---|---|---|---|
| Class | Three compartments: name; attributes; operations. The lower two may be hidden when not relevant. | class Order {
-Money total
+pay()
} | |
| Abstract class | Name (and abstract operations) in italics, or the «abstract» keyword / {abstract} property. | class Shape {
<<abstract>>
} | |
| Interface | «interface» above the name; only operations, no state. The lollipop (circle on a stick) is the compact alternative. | class Payable {
<<interface>>
} | |
| Enumeration | «enumeration» above the name; the literals are listed in the second compartment. | class Status {
<<enumeration>>
NEW
PAID
} | |
| Static (class-scoped) member | Underlined attribute or operation — one value shared by all instances. | +count: int$ | |
| Derived attribute | A slash before the name: /age is computed from birthDate. | — | |
| Package | A tabbed folder grouping related classes; shown as a namespace in Mermaid. | namespace Billing {
class Invoice
} | |
| Note / comment | A dog-eared rectangle attached with a dashed line. | note for Order "text" |
Visibility marks: + − # ~
The character in front of an attribute or operation states who may access it. UML 2.5.1 §9.5.4 defines four values; Mermaid uses the same prefixes.
| Mark | Visibility | Accessible from | Typical use | Mermaid |
|---|---|---|---|---|
| + | Public | Any class | The API of the class: operations other classes call. | +total() Money |
| − | Private | The class itself only | Internal state — most attributes. | -date Date |
| # | Protected | The class and its subclasses | Hooks meant to be overridden; shared state for a hierarchy. | #id UUID |
| ~ | Package | Classes in the same package / namespace | Helpers used by sibling classes but not part of the public API. | ~helper() |
Full member syntax (UML 2.5.1 §9.5.4 and §9.6.4): visibility name : type [multiplicity] = default {property} for attributes — e.g. - tags : String [0..*] {ordered} — and visibility name(parameter : type, …) : returnType for operations — e.g. + pay(amount : Money) : bool. Mermaid writes the type first: -Money total, +pay(Money amount) bool.
Relationship arrows
Read the line from the end without the marker toward the end with it: the triangle points at the parent, the diamond sits on the whole, the dependency arrow points at the thing being used.
| Symbol | Relationship | Line end | Meaning | Example | Mermaid |
|---|---|---|---|---|---|
| Association | Plain line, optional name and role labels | A structural link: objects of one class know about objects of the other. Navigable both ways unless an arrow says otherwise. | Customer — Order | Customer -- Order | |
| Directed (navigable) association | Open arrowhead at the navigable end | Only the source holds a reference to the target. | Order → Product | Order --> Product | |
| Aggregation (shared) | Hollow diamond on the whole | "Has a" where the part can exist without the whole and may belong to several wholes. | Department ◇— Teacher | Department o-- Teacher | |
| Composition | Filled diamond on the whole | "Owns a": the part cannot exist without the whole and is deleted with it; belongs to one whole at a time. | Order ◆— OrderLine | Order *-- OrderLine | |
| Generalisation (inheritance) | Solid line, hollow triangle at the parent | "Is a": the child inherits attributes, operations and associations of the parent. | User ◁— Customer | User <|-- Customer | |
| Realisation (implements) | Dashed line, hollow triangle at the interface | The class implements every operation the interface declares. | Payable ◁┄ CardPayment | Payable <|.. CardPayment | |
| Dependency | Dashed line, open arrowhead at the supplier | A temporary use: parameter, local variable, return type. Changing the supplier may affect the client. Often stereotyped «use», «create», «call». | InvoiceService ┄▷ Order | InvoiceService ..> Order | |
| Association class | A class box joined to an association by a dashed line | An association that has its own attributes: Enrolment between Student and Course carries the grade. | Student — Course + Enrolment | — |
Multiplicity
Written at the end of an association or aggregation, next to the class whose instances are being counted. UML 2.5.1 §7.5.4 defines the form lower..upper; * alone means 0..*.
| Notation | Reads as | Example | Mermaid |
|---|---|---|---|
| 1 | Exactly one | Every order belongs to exactly one customer | Order "*" --> "1" Customer |
| 0..1 | Zero or one (optional) | An order has at most one discount code | Order "1" --> "0..1" Discount |
| * or 0..* | Zero or more | A customer has placed any number of orders | Customer "1" --> "*" Order |
| 1..* | One or more | An order contains at least one line | Order "1" *-- "1..*" OrderLine |
| n | Exactly n | A chess position has 2 kings | Position "1" *-- "2" King |
| m..n | Between m and n | A team has 5 to 7 members | Team "1" o-- "5..7" Member |
Stereotypes and keywords
| Stereotype | Applies to | Meaning | Mermaid |
|---|---|---|---|
| «interface» | Classifier | Declares operations only; realised by classes. | <<interface>> |
| «abstract» | Classifier | Cannot be instantiated; equivalent to an italic name. | <<abstract>> |
| «enumeration» | Classifier | A fixed set of literal values. | <<enumeration>> |
| «service», «entity», «controller» | Classifier | Architectural role (common in Spring / DDD projects; not defined by UML itself). | <<service>> |
| «use», «create», «call», «import» | Dependency | Standard UML dependency kinds that say how the client depends on the supplier. | A ..> B : «create» |
| {abstract}, {readOnly}, {ordered}, {unique} | Members | Properties in braces after a member or multiplicity. | — |
What is a class diagram?
A class diagram is the UML structure diagram that shows the classes of an object-oriented system, what each class knows (attributes) and does (operations), and how the classes relate — inheritance, composition, association, dependency. It is drawn at three levels of detail: conceptual (domain classes only), specification (interfaces and types) and implementation (every member with visibility and type, ready to code from).
What is the difference between aggregation and composition?
Both are whole–part associations drawn with a diamond on the whole. Composition (filled diamond) is exclusive and life-dependent: an OrderLine exists inside exactly one Order and is deleted with it. Aggregation (hollow diamond) is shared and independent: a Teacher belongs to a Department but survives its closure and may serve two departments. If you are unsure, use a plain association — UML 2.5.1 itself leaves the precise semantics of shared aggregation to the modeller.
| Aggregation ◇ | Composition ◆ | |
|---|---|---|
| Part exists without whole | Yes | No |
| Part shared by several wholes | Allowed | Never (multiplicity at the whole end is 0..1 or 1) |
| Deleting the whole | Parts survive | Parts are deleted too |
| Typical code | List of references | Owned objects, cascade delete |
| Example | Playlist – Song, Department – Teacher | Order – OrderLine, House – Room |
What is the difference between generalisation and realisation?
Both end in a hollow triangle. Generalisation is a solid line between two classes (or two interfaces): the child inherits everything from the parent. Realisation is a dashed line from a class to an interface: the class promises to implement the interface's operations but inherits no state. In code, generalisation is extends and realisation is implements.
Which way do the arrows point?
Always toward the more general or more stable thing. The generalisation triangle points at the parent, the realisation triangle at the interface, the dependency arrow at the supplier (the class being used), the navigable-association arrow at the class being referenced. The diamond is not an arrow: it sits on the whole, and the part is at the other end.
What does a class diagram look like with these symbols?
A small order-management model: Customer inherits from User; a Customer places many Orders; an Order is composed of OrderLines that refer to Products; CardPayment realises the Payable interface that Order depends on; InvoiceService has a «use» dependency on Order. Below it, the same model as Mermaid code you can paste into any Mermaid renderer.
classDiagram
class User {
<<abstract>>
#UUID id
-String email
+login() bool
}
class Customer {
-int loyaltyPoints
+placeOrder() Order
}
class Order {
-Date date
-OrderStatus status
+total() Money
}
class OrderLine {
-int quantity
+subtotal() Money
}
class Product {
-String sku
-Money price
}
class Payable {
<<interface>>
+pay(Money amount) bool
}
class CardPayment {
-String last4
+pay(Money amount) bool
}
class OrderStatus {
<<enumeration>>
NEW
PAID
SHIPPED
}
User <|-- Customer : inheritance
Customer "1" --> "0..*" Order : places
Order "1" *-- "1..*" OrderLine : contains
OrderLine "*" --> "1" Product
Payable <|.. CardPayment : realization
Order ..> Payable : uses
Order --> OrderStatusIn Mermaid, the marker goes on the side it belongs to: User <|-- Customer puts the triangle on User; Order *-- OrderLine puts the filled diamond on Order; multiplicities are quoted strings on either side of the arrow.
Class diagram vs ER diagram — what is the difference?
An ER diagram models data to be stored — tables, columns, keys and cardinality — and has no operations or inheritance. A class diagram models the program — attributes and behaviour, inheritance, interfaces, dependencies — and includes classes that never touch the database, such as services and controllers. Entities in an ERD usually map to the persistent classes of the class diagram.
Crow's foot, Chen and UML data-modelling notation are compared in the ER diagram symbols reference.
What are the most common class diagram mistakes?
Most are a wrong line end — a filled diamond where the parts are shared, a triangle pointing at the child — or members that leak implementation detail into a conceptual diagram.
| Mistake | Why it is wrong | Fix |
|---|---|---|
| Triangle on the child | Reads as the parent inheriting from the child. | Hollow triangle touches the parent. |
| Diamond on the part | Reads as the part owning the whole. | Diamond touches the whole. |
| Composition for shared parts | A Song is not deleted when a Playlist is. | Use aggregation or a plain association. |
| Dependency where an association is meant | A dashed arrow says "uses briefly"; a stored reference is an association. | Solid line (with arrowhead if one-way). |
| Missing multiplicity | Reader cannot tell one-to-one from one-to-many. | Put a multiplicity at both ends of every association. |
| Foreign keys as attributes | customerId in Order duplicates the association. | Draw the association; drop the id attribute in conceptual and specification diagrams. |
| Getters and setters listed | Noise — they add nothing to the model. | Show only operations that carry meaning (place, cancel, total). |
| Interface with attributes | Interfaces declare behaviour, not state. | Move state into an abstract class. |
What do real diagrams with these symbols look like?
Live diagrams from the public ChartCraft gallery, each generated from a plain-English description — open one to see the prompt that produced it.
Questions
What are the symbols used in a class diagram?
Boxes for classifiers — class (three compartments), abstract class (italic name), interface («interface»), enumeration («enumeration»), package — and six kinds of line: association, aggregation (hollow diamond), composition (filled diamond), generalisation (hollow triangle), realisation (dashed line, hollow triangle) and dependency (dashed arrow).
What do +, -, # and ~ mean in a class diagram?
Visibility: + public (any class may access it), - private (only the class itself), # protected (the class and its subclasses), ~ package (classes in the same package). The mark goes in front of each attribute and operation.
What does the hollow diamond mean in a class diagram?
Aggregation — a shared whole–part relationship. The diamond sits on the whole; the part can exist without the whole and may belong to more than one whole. A filled diamond is composition, where the part is owned exclusively and destroyed with the whole.
Which way does the inheritance arrow point?
The hollow triangle touches the parent (superclass). Read it as "Customer is a User" with the triangle on User. In Mermaid: User <|-- Customer.
What is the difference between a dashed and a solid line?
A solid line is a structural relationship that exists for the life of the objects: association, aggregation, composition or generalisation. A dashed line is weaker: dependency (open arrowhead — one class uses another briefly) or realisation (hollow triangle — a class implements an interface).
What does 1..* mean?
One or more. Multiplicity is written at the end of an association next to the class being counted: Order 1 — 1..* OrderLine means every order has at least one line. Other common values: 1 (exactly one), 0..1 (optional), * (zero or more).
How do I write a class diagram in Mermaid?
Start with classDiagram, declare each class with its members in braces (type before name, visibility prefix +, -, #, ~), then one relationship per line using the arrow notation: <|-- inheritance, <|.. realisation, *-- composition, o-- aggregation, --> directed association, ..> dependency. Multiplicities are quoted strings beside the arrow.
Which UML version defines these symbols?
UML 2.5.1, published by the OMG in December 2017 (document formal/2017-12-05). Classes are in clause 11, associations and multiplicity in clause 7 and 9, dependencies in clause 7.8.