How to draw a UML class diagram

A class diagram shows the types in a program, what they hold and do, and how they relate. Draw one to design or explain code structure.

A UML class diagram: Customer and Admin inherit from User; a Customer places Orders; an Order is made of OrderLines. A UML class diagram: Customer and Admin inherit from User; a Customer places Orders; an Order is made of OrderLines.
Users and orders: inheritance towards the parent, composition towards the whole.

Step by step

  1. Pick UML class from the Diagram menu, click Class, then click the board. Type the name, then one member per line: attributes, and operations with parentheses, like +signIn().

    A User class with an email attribute and a signIn() operation, in compartments. A User class with an email attribute and a signIn() operation, in compartments.
  2. Add the other classes the same way. Each one grows to fit its members.

    Two more classes below: Customer, with an address and placeOrder(), and Admin, with refund(order). Two more classes below: Customer, with an address and placeOrder(), and Admin, with refund(order).
  3. Pick a relation and drag from one class to the other: Inheritance from the child to the parent, Composition and Aggregation from the part to the whole.

    Customer and Admin joined to User by inheritance arrows with hollow triangles. Customer and Admin joined to User by inheritance arrows with hollow triangles.

Tips

Mermaid

Paste this onto the board, or use Board menu → Import Mermaid…; Export Mermaid… writes a board back as text.

classDiagram
  class User {
    -String email
    +signIn()
  }
  User <|-- Customer
  User <|-- Admin
  Customer --> Order : places

Relations: <|-- inheritance, <|.. realization, *-- composition, o-- aggregation, --> association, ..> dependency, -- and .. links. More on Mermaid import and export.