Class diagram examples

UML class diagram examples generated from text

UML class diagram examples with attributes, methods, and inheritance — generated from plain English, no XML. Copy the prompt and make your own.

Open the studio → Learn more Free — 3 diagrams, no account

Prose in. Diagram out.

The prompt

An Animal has a name and can makeSound(). Dog and Cat inherit from Animal. A Shelter holds many Animals.

Try this in the studio →

ChartCraft draws

UML class diagram example: Animal class hierarchyAnimalname: stringmakeSound()Dogfetch()Catscratch()Shelteraddress: stringintake(a)holds *

More UML class diagram examples

Generated with ChartCraft and published in the examples gallery — open one to see its prompt, or use it as a starting point.

The notation, in 30 seconds

The UML class box and the five arrows that matter. Arrowheads carry the meaning — hollow triangle for “is-a”, diamonds for “owns”.

ElementWhat it means
Class boxThree stacked compartments: name, attributes (name: type), methods (call()).
Inheritance (hollow triangle)“Is-a”. Dog ▷ Animal. The triangle touches the parent.
Realization (dashed + triangle)“Implements”. A class fulfilling an interface's contract.
Association (plain line)“Knows about”. Add multiplicities at the ends: 1, 0..1, *.
Aggregation (hollow diamond)“Has, but doesn't own” — parts survive the whole. Team ◇ Player.
Composition (filled diamond)“Owns” — parts die with the whole. Order ◆ OrderLine.

Best practices — and the classic mistakes

Do

  • Model the domain, not the framework — leave controllers, DTOs, and helpers out unless the diagram is about them.
  • Prefer composition arrows over inheritance when the relationship is “owns” rather than “is”.
  • Put multiplicities on every association — 1, 0..1, or *; unlabelled lines invite wrong assumptions.
  • Abstract classes in italics (or marked abstract) so readers know they're never instantiated.
  • One diagram, one story: an inheritance view and an ownership view beat one diagram showing everything.

Avoid

  • Inheritance used for code reuse (“Car extends Engine”) — that relationship is composition.
  • Arrowheads swapped — the hollow triangle must touch the parent, diamonds touch the owner.
  • Every private field and getter listed — the diagram becomes a code dump nobody reads.
  • Missing multiplicities, leaving readers to guess whether a relationship is 1:1 or 1:many.

Questions

How were these UML class diagram examples made?

Each example was generated by ChartCraft from a plain-English prompt, then laid out automatically — the same way you'd make your own. Click any example to see its full page.

Can I use these UML class diagram examples as templates?

Yes — open an example, copy its prompt into the studio, then edit it in plain English to fit your case.

What's the difference between aggregation and composition?

Both are “has-a” diamonds. Composition (filled) means exclusive ownership — delete the Order and its OrderLines go with it. Aggregation (hollow) means the parts live independently — disband a Team and the Players remain.

Should every class in my codebase appear in the diagram?

No. A useful class diagram tells one story about the domain — 5 to 12 classes. Generate separate diagrams for separate subsystems rather than one wall-sized chart.

Is it free?

Your first 3 diagrams are free with no account, then 5 a month on a free account.

Related

Try it now — your first three are free.

Open the studio →