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>>.

SymbolElementNotationMermaid
ClassThree compartments: name; attributes; operations. The lower two may be hidden when not relevant.class Order { -Money total +pay() }
Abstract className (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) memberUnderlined attribute or operation — one value shared by all instances.+count: int$
Derived attributeA slash before the name: /age is computed from birthDate.—
PackageA tabbed folder grouping related classes; shown as a namespace in Mermaid.namespace Billing { class Invoice }
Note / commentA 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.

MarkVisibilityAccessible fromTypical useMermaid
+PublicAny classThe API of the class: operations other classes call.+total() Money
−PrivateThe class itself onlyInternal state — most attributes.-date Date
#ProtectedThe class and its subclassesHooks meant to be overridden; shared state for a hierarchy.#id UUID
~PackageClasses in the same package / namespaceHelpers 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.

SymbolRelationshipLine endMeaningExampleMermaid
AssociationPlain line, optional name and role labelsA structural link: objects of one class know about objects of the other. Navigable both ways unless an arrow says otherwise.Customer — OrderCustomer -- Order
Directed (navigable) associationOpen arrowhead at the navigable endOnly the source holds a reference to the target.Order → ProductOrder --> 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 ◇— TeacherDepartment o-- Teacher
CompositionFilled 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 ◆— OrderLineOrder *-- OrderLine
Generalisation (inheritance)Solid line, hollow triangle at the parent"Is a": the child inherits attributes, operations and associations of the parent.User ◁— CustomerUser <|-- Customer
Realisation (implements)Dashed line, hollow triangle at the interfaceThe class implements every operation the interface declares.Payable ◁┄ CardPaymentPayable <|.. CardPayment
DependencyDashed line, open arrowhead at the supplierA temporary use: parameter, local variable, return type. Changing the supplier may affect the client. Often stereotyped «use», «create», «call».InvoiceService ┄▷ OrderInvoiceService ..> Order
Association classA class box joined to an association by a dashed lineAn 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..*.

NotationReads asExampleMermaid
1Exactly oneEvery order belongs to exactly one customerOrder "*" --> "1" Customer
0..1Zero or one (optional)An order has at most one discount codeOrder "1" --> "0..1" Discount
* or 0..*Zero or moreA customer has placed any number of ordersCustomer "1" --> "*" Order
1..*One or moreAn order contains at least one lineOrder "1" *-- "1..*" OrderLine
nExactly nA chess position has 2 kingsPosition "1" *-- "2" King
m..nBetween m and nA team has 5 to 7 membersTeam "1" o-- "5..7" Member

Stereotypes and keywords

StereotypeApplies toMeaningMermaid
«interface»ClassifierDeclares operations only; realised by classes.<<interface>>
«abstract»ClassifierCannot be instantiated; equivalent to an italic name.<<abstract>>
«enumeration»ClassifierA fixed set of literal values.<<enumeration>>
«service», «entity», «controller»ClassifierArchitectural role (common in Spring / DDD projects; not defined by UML itself).<<service>>
«use», «create», «call», «import»DependencyStandard UML dependency kinds that say how the client depends on the supplier.A ..> B : «create»
{abstract}, {readOnly}, {ordered}, {unique}MembersProperties 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 wholeYesNo
Part shared by several wholesAllowedNever (multiplicity at the whole end is 0..1 or 1)
Deleting the wholeParts surviveParts are deleted too
Typical codeList of referencesOwned objects, cascade delete
ExamplePlaylist – Song, Department – TeacherOrder – 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.

UML class diagram of an order management model«interface» Payable+ pay(amount: Money): boolUser# id: UUID- email: String+ login(): boolCustomer- loyaltyPoints: int+ placeOrder(): OrderOrder- date: Date- status: OrderStatus+ total(): MoneyOrderLine- quantity: int+ subtotal(): MoneyProduct- sku: String- price: MoneyCardPayment- last4: String+ pay(amount: Money): boolInvoiceService+ render(order: Order): PDF1 places 0..*1 contains 1..** refers to 1uses«use»
Rendered by the engine behind the class diagram generator. This static preview draws every connector with the same arrowhead; the studio export uses the UML markers in the table above. Labels on the lines carry the multiplicity and role.
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 --> OrderStatus

In 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.

MistakeWhy it is wrongFix
Triangle on the childReads as the parent inheriting from the child.Hollow triangle touches the parent.
Diamond on the partReads as the part owning the whole.Diamond touches the whole.
Composition for shared partsA Song is not deleted when a Playlist is.Use aggregation or a plain association.
Dependency where an association is meantA dashed arrow says "uses briefly"; a stored reference is an association.Solid line (with arrowhead if one-way).
Missing multiplicityReader cannot tell one-to-one from one-to-many.Put a multiplicity at both ends of every association.
Foreign keys as attributescustomerId in Order duplicates the association.Draw the association; drop the id attribute in conceptual and specification diagrams.
Getters and setters listedNoise — they add nothing to the model.Show only operations that carry meaning (place, cancel, total).
Interface with attributesInterfaces 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.

More symbol references

Skip the shape palette — describe the diagram in plain English.

Class diagram generator →