What a class diagram shows
A UML class diagram has three layers per class: the class name at the top, attributes (data fields) in the middle, and methods (functions) at the bottom. Relationships between classes are drawn as lines with specific arrow types that indicate inheritance, composition, aggregation, or association.
Class diagrams are used to design object-oriented systems before writing code, to document an existing codebase for onboarding, and to communicate system architecture to stakeholders without writing a line of code.
The notation at a glance
| Symbol | Meaning | Example |
|---|---|---|
+ before attribute/method | Public visibility | + name: String |
- before attribute/method | Private visibility | - password: String |
# before attribute/method | Protected visibility | # id: Int |
| Solid line with open triangle arrow | Inheritance (generalization) | Dog → Animal |
| Dashed line with open triangle arrow | Interface implementation (realization) | PayPalGateway ⇢ PaymentGateway |
| Solid line with filled diamond | Composition (part-of, lifecycle dependency) | Engine ◆── Car |
| Solid line with open diamond | Aggregation (has-a, independent lifecycle) | Student ◇── University |
| Plain solid line | Association (uses, knows about) | Order ── Customer |
How to draw one online free
Option 1: TheFreeAITools Class Diagram Maker (no signup)
The free class diagram maker lets you add classes, define attributes and methods with visibility modifiers, and draw relationships by connecting classes. Export to PNG or SVG when done. No account required.
Best for: quick diagrams, student assignments, documentation screenshots.
Option 2: Draw.io / diagrams.net (no signup)
Draw.io is a browser-based diagramming tool with a dedicated UML class diagram template. It saves locally or to Google Drive and requires no account for local use. It has more layout options than most free tools and exports to XML, PNG, SVG, or PDF.
Best for: complex diagrams with many classes and relationships, when you want to combine UML with other diagram types (flowcharts, sequence diagrams) in one file.
Option 3: Mermaid.js (text-based, no signup)
Mermaid is a Markdown-like syntax that generates diagrams from text. A class diagram in Mermaid looks like this:
classDiagram
class Animal {
+String name
+int age
+speak() String
}
class Dog {
+String breed
+fetch() void
}
Animal <|-- DogPaste this into the Mermaid Live Editor (mermaid.live) and it renders instantly. No account. The main advantage: the diagram is version-controllable as a text file, which makes it ideal for documenting code in a Git repository (GitHub and GitLab both render Mermaid natively in Markdown files).
Worked example: an e-commerce order system
Here is what a minimal class diagram looks like for an online order system, using correct UML notation:
- Customer has:
- id: Int,+ name: String,+ email: String, method:+ placeOrder(): Order - Order has:
- orderId: Int,- createdAt: DateTime,- status: String, method:+ calculateTotal(): Float - OrderItem has:
- quantity: Int,- unitPrice: Float - Product has:
- sku: String,+ name: String,- stock: Int
Relationships: Customer associates with Order (1 to many). Order composes OrderItem (filled diamond — items don't exist without an order). OrderItem associates with Product (many items can reference the same product).
Common mistakes in class diagrams
- Using composition when aggregation is correct — composition means the child cannot exist without the parent (Engine without a Car is meaningless). Aggregation means they can (a Student can exist without a University if they graduate). Most relationships in real systems are associations, not composition.
- Putting too many attributes on the diagram — a class diagram for communication should show 3–5 key attributes and methods per class, not every field in the database schema. A database schema tool is better for that.
- Confusing realization (interface) with inheritance — the line type matters. A class implementing an interface uses a dashed arrow; a class inheriting from a parent class uses a solid arrow with an open triangle.
ER diagram vs class diagram: which do you need?
An ER diagram (entity-relationship diagram) models database structure — tables, foreign keys, cardinality. A class diagram models object-oriented software — classes, methods, inheritance. They look similar but serve different purposes.
If you're designing a database: use an ER diagram maker. If you're designing classes in Python, Java, or TypeScript: use a class diagram maker.
Where to go next
Once you have a class diagram, the natural next step is a sequence diagram (to show how objects interact over time) or a component diagram (to show how the system is packaged and deployed). Both are available in the free diagram tools collection.